Skip to content

Add a Dockerfile for running the backend as a container - #14

Open
coderback wants to merge 1 commit into
mainfrom
backend-dockerfile
Open

coderback wants to merge 1 commit into
mainfrom
backend-dockerfile

Conversation

@coderback

Copy link
Copy Markdown
Owner

What

  • packages/backend/Dockerfile: two-stage build on node:22-slim.
    • Build stage: npm install, then npm run build (which already runs prisma generate), checks that dist/main.js exists, then prunes dev dependencies.
    • Runtime stage: runs node dist/main directly as the non-root node user, so SIGTERM reaches the app and its existing shutdown hooks run.
    • Copies data/ into the image, because the exercises module reads data/exercises.json from disk at runtime.
    • Installs OpenSSL, which Prisma's query engine needs and the slim image doesn't ship.
  • packages/backend/.dockerignore: keeps node_modules, dist, tests and every .env* file out of the build context, so secrets never end up in an image.
  • README: a short "Running the backend as a container" section under the Railway deploy notes.

Why

The backend could only be built by Railway's Nixpacks. A Dockerfile lets the same API run on any container host (local, another PaaS, or a cluster later) without changing how Railway deploys today.

Not changed

  • railway.toml still builds with Nixpacks; this PR doesn't switch Railway to the Dockerfile.
  • Migrations don't run on container start; prisma migrate deploy stays a separate release step.

Tested locally

Against a throwaway Postgres 16 with dummy Supabase and Azure OpenAI keys:

  • All 23 migrations applied with prisma migrate deploy from the image's build stage.
  • GET / and GET /health return 200, and an authenticated route returns 401 without a token.
  • With the database stopped, /health returns 503.
  • 876 exercises loaded from data/.
  • The process runs as node, and .env isn't in the image.
  • docker stop exits with code 0.

Not tested with real Supabase or Azure OpenAI credentials.

For the reviewer

  • The image is about 600 MB, mostly the Node base image and production dependencies.
  • package-lock.json is gitignored, so dependency versions can differ between image builds.

🤖 Generated with Claude Code

- Multi-stage build on node:22-slim: install, npm run build (which runs
  prisma generate), prune dev deps
- Runtime image runs node dist/main as the non-root node user, so SIGTERM
  reaches the app and its shutdown hooks run
- Copy data/ into the image; the exercises module reads
  data/exercises.json from disk at runtime
- .dockerignore keeps node_modules, dist, tests and .env files out of
  the build context
- Document building and running the image in the README; Railway still
  builds with Nixpacks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
grit-demo Ready Ready Preview Nov 23, 2026 7:44pm UTC

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant