Build production-ready multi-stage Dockerfile for the frontend #135
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
frontend/Dockerfilecurrently runsnpm run dev(Vite hot-reload dev server) against a bind-mounted source tree. This means:What to do
Replace
frontend/Dockerfilewith a two-stage build. The project uses SvelteKit with@sveltejs/adapter-node, so the build output is a Node.js server that can be run withnode build/index.js.Stage 1 — Build (Node + all dependencies): install deps, run
npm run build, produce thebuild/directory.Stage 2 — Runtime (Node slim): copy only
build/and the productionnode_modules, nothing else.Environment variables at runtime
SvelteKit's Node adapter reads these at startup — they must be injected via Docker environment, not baked into the image:
API_INTERNAL_URLhttp://backend:8080)PORT3000)HOST0.0.0.0in Docker)ORIGINhttps://familienarchiv.example.com) — required by SvelteKit for CSRF protectionORIGINis easy to forget and causes cryptic CSRF errors if missing. Document it in.env.example.Additional hardening
RUN addgroup -S app && adduser -S app -G appandUSER appin the runtime stage..envor any secrets into the image — all config comes from the runtime environment.Acceptance criteria
docker build -t familienarchiv-frontend .fromfrontend/produces a self-contained image.docker run -e API_INTERNAL_URL=... -e ORIGIN=... familienarchiv-frontendstarts and serves the app.