fix(docker): auto-run prisma db push on web container start (Closes #6)#16
Merged
Conversation
#6) `docker compose up -d` against an empty Postgres was fatal-failing on the engine startup with `relation "schedulers" does not exist` because nothing in the compose stack ran the Prisma migration. The k8s deployment uses a real init container for this; for the docker-compose / single-host install path we run the same `prisma db push` from a shell wrapper before exec'ing into Next.js. Verified by cloning v0.1.2 fresh, `docker compose up -d`, and watching the engine fatal-crash. With the wrapper the engine starts clean against the migrated DB. Opt-out via `SKIP_DB_MIGRATE=true` for ops setups that prefer to time migrations externally (blue/green deploys, etc.).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docker compose up -dagainst an empty Postgres was fatal-failing on the engine withrelation "schedulers" does not existbecause nothing in the compose stack runs the Prisma migration.This PR adds a startup wrapper to the web container that runs
npx prisma db pushbefore exec'ing into Next.js. The k8s deployment continues to use its own init container (untouched); this just covers the docker-compose / single-host path.Repro (before this PR)
```bash
git clone --branch v0.1.2 https://github.com/EnterpriseX-Platform/RunLoop runloop-test
cd runloop-test && cp .env.example .env
scripts/gen-secrets.sh >> .env
docker compose up -d
docker compose logs runloop-engine
{"level":"fatal","error":"failed to load schedulers: failed to query schedulers:
ERROR: relation "schedulers" does not exist (SQLSTATE 42P01)"}
```
The web container would happily serve the login page, but every API call would hit a dead engine.
Fix
apps/runloop/docker-entrypoint.sh:```sh
if [ "$SKIP_DB_MIGRATE" != "true" ]; then
npx prisma db push --skip-generate --accept-data-loss
fi
exec node server.js
```
prisma db pushis idempotent — repeated runs against an in-sync schema cost ~400 ms and make no changes, so leaving this on permanently is fine for restarts.SKIP_DB_MIGRATE=trueopt-out is there for ops setups that prefer timing migrations externally (blue/green deploys with a coordinated migration job).Closes
Closes #6 — that issue was about validating
docker compose upon a clean VM. It validated negatively; this PR makes it pass.Test plan
docker build apps/runloopsucceeds (verified locally, 53 s with cache)ENTRYPOINT [/app/docker-entrypoint.sh]docker compose up -dagainst a fresh volume produces healthy engine + working login on:3000/runloop/login