396ebf9837
Deploy / deploy (push) Successful in 3m45s
The deploy workflow pulled, built and started the app, but never applied migrations. Shipping a change that adds a table therefore broke the app until someone remembered to migrate by hand -- the new api_keys table would have done exactly that to the settings page. The workflow now builds, applies pending migrations, and only then starts the app. A failed migration exits non-zero, so the deploy fails instead of starting an app whose schema is behind its code. Because `up -d` is never reached in that case, production keeps serving the previous containers. Migrations run through a new `migrate` compose service built from the Dockerfile's builder stage, rather than `docker compose exec app npx prisma migrate deploy` as the README previously suggested. The production image copies prisma/ and node_modules/.prisma but not the Prisma CLI, which is a devDependency and is absent from the standalone bundle, so that command would have had npx download Prisma inside the container at runtime as the unprivileged nextjs user. The builder stage has the CLI and its engines already. The service sits behind a `tools` profile so `docker compose up` never starts it, and takes DATABASE_URL from compose rather than a .env file -- dotenv does not override variables that are already set, so the compose value wins. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
37 lines
946 B
YAML
37 lines
946 B
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
container:
|
|
volumes:
|
|
- /opt:/opt
|
|
|
|
steps:
|
|
- name: Deploy
|
|
run: |
|
|
cd /opt/xbid
|
|
|
|
git pull
|
|
|
|
# Build both images up front. `migrate` targets the Dockerfile's
|
|
# builder stage, which `app` also builds through, so the layers are
|
|
# shared and this costs no extra build time. The profile is named
|
|
# explicitly rather than relying on a service name activating it.
|
|
docker compose --profile tools build app migrate
|
|
|
|
# Apply pending migrations before the new app serves traffic. This
|
|
# exits non-zero if a migration fails, failing the deploy rather than
|
|
# starting an app whose schema is behind its code.
|
|
docker compose --profile tools run --rm migrate
|
|
|
|
docker compose up -d
|
|
|
|
docker image prune -f
|