From 80d7ae14ba413e90720dff3783c8d9239f7337ad Mon Sep 17 00:00:00 2001 From: openhands Date: Sun, 27 Sep 2026 18:57:10 +0200 Subject: [PATCH] fix(ci): fail fast when the deploy dir has no DATABASE_URL pnpm db:migrate runs on the host and reads DATABASE_URL from the deploy directory's .env. When that variable was missing the deploy had already built an image and run the browser gate before pnpm db:migrate aborted on an empty value, so a release was paid for in full and then thrown away. Check for the variable right after the .env is copied, before the build, and say plainly that the live release was not touched. The deploy test fixture gains a DATABASE_URL so it mirrors a working deploy directory instead of the broken one. --- scripts/ci-deploy.sh | 12 ++++++++++++ src/lib/ci-deploy.test.ts | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/ci-deploy.sh b/scripts/ci-deploy.sh index 8a9a1c80..9bf6973b 100644 --- a/scripts/ci-deploy.sh +++ b/scripts/ci-deploy.sh @@ -92,6 +92,18 @@ for managed_name in epicnext-cms epicnext-cms-app; do docker inspect --format '{{.Name}} running={{.State.Running}} pid={{.State.Pid}} image={{.Image}}' "$managed_name" 2>/dev/null || true done [ "$deploy_dir/.env" -ef .env ] || cp "$deploy_dir/.env" .env + +# De migraties draaien op de host tegen DATABASE_URL, niet in de container. Die +# waarde staat alleen in $deploy_dir/.env, dus controleer hem hier: anders +# bouwen we eerst een image en doorlopen we de browsergate voordat `db:migrate` +# op een lege DATABASE_URL stukloopt. Dat is een halve release voor niets. +if ! grep -qs '^DATABASE_URL=' .env; then + echo "Error: DATABASE_URL ontbreekt in $deploy_dir/.env" >&2 + echo " Zet daar een DATABASE_URL (mysql://user:pass@host:3306/db) en draai opnieuw." >&2 + echo " De live release is niet aangeraakt; deze release is niet uitgerold." >&2 + exit 1 +fi + pnpm install --frozen-lockfile pnpm exec playwright install chromium diff --git a/src/lib/ci-deploy.test.ts b/src/lib/ci-deploy.test.ts index ee7112e5..0eb76b15 100644 --- a/src/lib/ci-deploy.test.ts +++ b/src/lib/ci-deploy.test.ts @@ -33,7 +33,12 @@ function simulate( const dir = mkdtempSync(join(tmpdir(), "cms-deploy-test-")); try { mkdirSync(join(dir, "production")); - writeFileSync(join(dir, "production", ".env"), 'HOTEL_NAME="Test Hotel"\n'); + // Een werkende deploymap heeft een DATABASE_URL; die gebruikt + // scripts/ci-deploy.sh voor de migraties op de host. + writeFileSync( + join(dir, "production", ".env"), + 'HOTEL_NAME="Test Hotel"\nDATABASE_URL="mysql://test:test@127.0.0.1:3306/test"\n', + ); if (previous) writeFileSync(join(dir, previous), "old\n"); if (both) writeFileSync(join(dir, "epicnext-cms-app"), "old\n"); const result = spawnSync(bash, [resolve(root, "scripts/ci-deploy.sh")], {