feat(docker): add production image and Docker Hub publishing - #186
Merged
Conversation
The only image so far was the development one: it bind-mounts the source and runs `next dev`, so it cannot be distributed. This adds a real production image and the workflow that publishes it. The build is multi-stage. Next.js now emits a standalone server bundle, so the runner carries the traced runtime only instead of the full node_modules. It runs as the unprivileged `node` user and exposes a healthcheck against /api/health. Migrations are applied by the entrypoint before the server starts. The Prisma CLI could not simply be copied out of the app dependencies (its config loader pulls packages that the Next.js trace drops), so it gets its own install tree under /opt/prisma, pinned to the lockfile version. Set RUN_MIGRATIONS=false when a separate job owns the schema. The former Dockerfile becomes Dockerfile.dev and compose.yml points at it, so the local stack is unchanged. Verified by building the image and running it against the local database: migrations applied, /api/health returns db up, /login serves 200.
Without a gate, anyone able to push a `v*` tag triggers an immediate public image push. The job now runs in the `dockerhub` environment, which requires a manual approval and is restricted to `main`, `develop` and release tags. The Docker Hub credentials move to that environment as well.
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.
Context
The repository only shipped a development image: it bind-mounts the source and runs
next dev, so it cannot be distributed. This adds a production image and the workflow that publishes it to Docker Hub.Changes
Dockerfileis now the production build: multi-stage (deps, Prisma CLI, Next build, runner), unprivilegednodeuser, healthcheck on/api/health.Dockerfile.dev;compose.ymlpoints at it, so the local stack is unchanged.next.config.tsemits a standalone server bundle, so the runner carries the traced runtime instead of the fullnode_modules.docker/entrypoint.shrefuses to start withoutDATABASE_URL, appliesprisma migrate deploy, then execs the server.RUN_MIGRATIONS=falseskips the migration step when a separate job owns the schema..github/workflows/docker-publish.ymlbuilds and pushes onv*.*.*tags, plus anedgetag on manual dispatch..dockerignoreextended, README documents the two images.Note on the Prisma CLI
It could not simply be copied out of the app dependencies: its config loader requires packages the Next.js trace drops, and it needs a writable engines directory. It gets its own install tree under
/opt/prisma, pinned to the lockfile version.Required repository settings
Secrets
DOCKERHUB_USERNAMEandDOCKERHUB_TOKEN. Optional variableDOCKERHUB_IMAGEto publish under a name other than the defaultwhitemuush/datashield.Verification
Image built locally and run against the development database: 30 migrations applied,
/api/healthreturns{"status":"ok","db":"up"},/loginserves 200. Lint and compliance hooks pass.