Skip to content

Commit b11ccce

Browse files
committed
Configure external databases during Playground boot
1 parent c46456d commit b11ccce

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

packages/runtime-playground/src/playground-cli-runner.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export async function startPlaygroundCliServer(spec: RuntimeCreateSpec, mounts:
140140
wp: localAssetServer?.url ?? wordpressStartupAsset?.wp,
141141
php: spec.environment.phpVersion,
142142
skipSqliteSetup: spec.environment.databaseSetup === "external",
143+
...externalDatabaseCliOptions(spec),
143144
...(spec.environment.extensions?.length ? { phpExtension: spec.environment.extensions.map((extension) => extension.manifest) } : {}),
144145
phpIniEntries: pluginRuntimePhpIniEntries(spec),
145146
"site-url": spec.preview?.siteUrl,
@@ -376,6 +377,20 @@ function runtimeAutoPrependPhpBody(spec: RuntimeCreateSpec): string {
376377
return `${runtimeEnv}${distributionBootstrapPhp(spec)}`
377378
}
378379

380+
function externalDatabaseCliOptions(spec: RuntimeCreateSpec): Record<string, string> {
381+
if (spec.environment.databaseSetup !== "external") return {}
382+
const host = spec.runtimeEnv?.DB_HOST
383+
if (!host) return {}
384+
const port = spec.runtimeEnv?.DB_PORT
385+
return {
386+
"db-engine": "mysql",
387+
"db-host": port ? `${host}:${port}` : host,
388+
"db-user": spec.runtimeEnv?.DB_USER ?? "root",
389+
"db-pass": spec.runtimeEnv?.DB_PASSWORD ?? "",
390+
"db-name": spec.runtimeEnv?.DB_NAME ?? "runtime",
391+
}
392+
}
393+
379394
function distributionBootstrapPhp(spec: RuntimeCreateSpec): string {
380395
const distribution = recipeDistribution(spec)
381396
if (!distribution) {

tests/playground-cli-runner-bootstrap-ini.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ try {
5656
},
5757
},
5858
},
59-
runtimeEnv: { TC_MYSQL_PORT: "33060" },
59+
runtimeEnv: { TC_MYSQL_PORT: "33060", DB_HOST: "127.0.0.1", DB_PORT: "33061", DB_USER: "runtime", DB_PASSWORD: "secret", DB_NAME: "runtime" },
6060
artifactsDirectory,
6161
}
6262

@@ -72,6 +72,11 @@ try {
7272
assert.equal(calls[0].workers, 6)
7373
assert.equal(calls[0].wordpressInstallMode, "do-not-attempt-installing")
7474
assert.equal(calls[0].skipSqliteSetup, true)
75+
assert.equal(calls[0]["db-engine"], "mysql")
76+
assert.equal(calls[0]["db-host"], "127.0.0.1:33061")
77+
assert.equal(calls[0]["db-user"], "runtime")
78+
assert.equal(calls[0]["db-pass"], "secret")
79+
assert.equal(calls[0]["db-name"], "runtime")
7580
assert.equal(shouldUseProgrammaticPlaygroundRunner(spec), false)
7681
assert.deepEqual(calls[0].phpIniEntries, { memory_limit: "512M" })
7782
assert.deepEqual(calls[0].phpExtension, ["/tmp/sodium/manifest.json"])

0 commit comments

Comments
 (0)