# syntax=docker/dockerfile:1.28 # check=error=true # One Dockerfile for every Next.js app in apps/. The build context is the repo root and APP names the # app's folder, so a new app needs no edit here. tools/deploy.sh builds and runs it; a build by hand also # needs --build-context appenv=. # Debian 13 (glibc) in every stage: the runner runs the native binaries (sharp) the build installed. # Change the tag and the digest together. ARG NODE_IMAGE=docker.io/library/node:24.22.0-trixie-slim@sha256:7f486cabe892bff8fef04c0f7da8dba84a560be3e4e2740b7a86afc57ebec315 # The workspace install, shared by every app. Only the manifests and the lockfile come in, so a source # edit never reinstalls dependencies. FROM ${NODE_IMAGE} AS deps ENV CI=true \ NEXT_TELEMETRY_DISABLED=1 WORKDIR /repo # The exact pnpm from the root packageManager field ("pnpm@"). COPY package.json ./ RUN --mount=type=cache,id=npm,target=/root/.npm \ npm install --global --no-audit --no-fund "pnpm@$(node -p "require('./package.json').packageManager.replace(/^pnpm@|\+.*$/g, '')")" COPY --parents pnpm-lock.yaml pnpm-workspace.yaml .npmrc* patches* **/package.json ./ RUN --mount=type=cache,id=pnpm-store,target=/pnpm-store \ pnpm install --frozen-lockfile --store-dir=/pnpm-store # next build for one app. The Turbopack cache mount keeps the next build of this app incremental. FROM deps AS build COPY . . ARG APP ARG NEXT_DEPLOYMENT_ID WORKDIR /repo/apps/${APP:?} # The app's env file comes from tools/deploy.sh as a bind mount: it's in no layer, and a changed value # reruns this step. next build inlines its public values and validates the rest. RUN --mount=type=cache,id=next-cache-${APP},target=/repo/apps/${APP}/.next/cache \ --mount=type=bind,from=appenv,source=.env.production,target=/repo/apps/${APP}/.env.production <<'SH' set -eu # next build type-checks against the declarations (dist/*.d.ts) of the projects the app's tsconfig.json # references, and no checkout holds them: build them first, as each project's typecheck target does. pnpm exec tsc --build --emitDeclarationOnly $(node -p "const ts = require('typescript'); ts.readConfigFile('tsconfig.json', ts.sys.readFile).config.references.map((r) => r.path).join(' ')") pnpm exec next build # next.config.ts writes these when it loads; a release without them breaks fonts, icons, or worker updates. # Only apps that ship a service worker write sw.js (the admin panel has none, 0062). test -d public/fonts && test -f public/icons/symbol-defs.svg \ || { echo 'next build did not write public/fonts and public/icons/symbol-defs.svg' >&2; exit 1; } if grep -q writeServiceWorker next.config.ts; then test -f public/sw.js || { echo 'next build did not write public/sw.js' >&2; exit 1; } fi # Standalone copies the env file; the container mounts it at start instead, so the image holds no secret. rm -f .next/standalone/apps/${APP}/.env* SH # The runtime image: the standalone server with its traced node_modules, public/, and .next/static. FROM ${NODE_IMAGE} AS runner # KEEP_ALIVE_TIMEOUT outlasts a proxy's usual 60 s upstream keepalive, so it never reuses a socket Node closed. ENV NODE_ENV=production \ NEXT_TELEMETRY_DISABLED=1 \ HOSTNAME=0.0.0.0 \ PORT=3000 \ KEEP_ALIVE_TIMEOUT=65000 ARG APP WORKDIR /app/apps/${APP} COPY --from=build /repo/apps/${APP}/.next/standalone /app COPY --from=build /repo/apps/${APP}/.next/static .next/static COPY --from=build /repo/apps/${APP}/public public # Every file belongs to root, so the app can't change its own code; only the image optimizer's cache is writable. RUN install -d -o node -g node .next/cache USER node EXPOSE 3000 # tools/deploy.sh swaps a release in only after this check passes. HEALTHCHECK --interval=10s --timeout=3s --start-period=30s --start-interval=2s --retries=3 \ CMD ["node", "-e", "fetch('http://127.0.0.1:' + process.env.PORT + '/healthz').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"] CMD ["node", "server.js"]