build: drop the Flutter builder stage from the Docker image

The Flutter SDK image is ~2.8 GB and filled Docker Desktop's VM disk
("read-only file system" while extracting a layer). Build the web bundle
on the host instead and COPY client/app/build/web into the 2-stage
(NestJS build -> slim runtime) image. .dockerignore keeps the bundle,
drops the platform scaffolding. README documents the host `flutter build
web` prerequisite.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-10 12:23:33 +02:00
co-authored by Claude Sonnet 5
parent f42aead5ca
commit 72367637aa
3 changed files with 31 additions and 22 deletions
+10 -3
View File
@@ -1,10 +1,17 @@
**/node_modules **/node_modules
**/dist
**/build
**/.dart_tool **/.dart_tool
**/coverage **/coverage
.git
**/*.log **/*.log
.git
.github
backend/dist
# Flutter platform scaffolding / caches — the build/web bundle IS needed.
client/app/android
client/app/ios
client/app/linux
client/app/macos
client/app/windows
client/app/.dart_tool
# Secrets: passed at runtime via env_file / bind mount, never baked in. # Secrets: passed at runtime via env_file / bind mount, never baked in.
backend/.env backend/.env
backend/serviceAccount.json backend/serviceAccount.json
+9 -12
View File
@@ -1,14 +1,11 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
#
# The Flutter web bundle is built on the HOST (it needs a ~2.8 GB SDK image
# otherwise). Before `docker compose build`, run:
# (cd client/app && flutter build web --release)
# This Dockerfile just copies client/app/build/web into the runtime image.
# --- 1. Flutter web build ------------------------------------------------- # --- 1. Backend build ---------------------------------------------------------
FROM ghcr.io/cirruslabs/flutter:stable AS web
WORKDIR /src
COPY client/app/pubspec.yaml client/app/pubspec.lock ./
RUN flutter pub get
COPY client/app/ ./
RUN flutter build web --release
# --- 2. Backend build --------------------------------------------------------
FROM node:20-bookworm-slim AS api-build FROM node:20-bookworm-slim AS api-build
WORKDIR /src WORKDIR /src
COPY backend/package.json backend/package-lock.json ./ COPY backend/package.json backend/package-lock.json ./
@@ -16,7 +13,7 @@ RUN npm ci
COPY backend/ ./ COPY backend/ ./
RUN npx prisma generate && npm run build RUN npx prisma generate && npm run build
# --- 3. Runtime ------------------------------------------------------------ # --- 2. Runtime -------------------------------------------------------------
FROM node:20-bookworm-slim AS runtime FROM node:20-bookworm-slim AS runtime
ENV NODE_ENV=production ENV NODE_ENV=production
WORKDIR /app WORKDIR /app
@@ -26,8 +23,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends openssl \
COPY --from=api-build /src/node_modules ./node_modules COPY --from=api-build /src/node_modules ./node_modules
COPY --from=api-build /src/dist ./dist COPY --from=api-build /src/dist ./dist
COPY --from=api-build /src/prisma ./prisma COPY --from=api-build /src/prisma ./prisma
# The Flutter web build; app.module reads WEB_CLIENT_DIR. # Pre-built Flutter web bundle from the host; app.module reads WEB_CLIENT_DIR.
COPY --from=web /src/build/web ./web COPY client/app/build/web ./web
ENV WEB_CLIENT_DIR=/app/web ENV WEB_CLIENT_DIR=/app/web
EXPOSE 3000 EXPOSE 3000
# Apply pending migrations, then boot. # Apply pending migrations, then boot.
+12 -7
View File
@@ -8,17 +8,22 @@ for the full architecture and phased roadmap.
## Run with Docker ## Run with Docker
```bash ```bash
cp backend/.env.example backend/.env # fill in the secrets cp backend/.env.example backend/.env # fill in the secrets
# put the Firebase service account at backend/serviceAccount.json (optional; push) # optional (push): put the Firebase service account at backend/serviceAccount.json
(cd client/app && flutter build web --release) # host build — see note below
docker compose up --build docker compose up --build
``` ```
`docker-compose.yml` starts PostgreSQL 16 and one `api` container (multi-stage `docker-compose.yml` starts PostgreSQL 16 and one `api` container (2-stage
`Dockerfile`: Flutter web build → NestJS build → slim runtime). The container `Dockerfile`: NestJS build → slim runtime). The container runs
runs `prisma migrate deploy` on start and serves the whole app — Flutter web `prisma migrate deploy` on start and serves the whole app — Flutter web
client + REST API — on <http://localhost:3000>. Requires Docker Compose v2. client + REST API — on <http://localhost:3000>. Requires Docker Compose v2.
Secrets are read from `backend/.env` and the service-account JSON is bind-
mounted read-only; neither is baked into the image. The Flutter web bundle is built **on the host** and copied in (a Flutter
builder stage would pull a ~2.8 GB SDK image). So `flutter build web` must
run before `docker compose build`. Secrets come from `backend/.env`
(unquoted, Compose v2 strips quotes) and the service-account JSON is
bind-mounted read-only — neither is baked into the image.
## Structure ## Structure