Files
anonymous_github/Dockerfile
T
tdurieux 06a098fba7 perf(deploy): faster builds and zero-downtime streamer rollover
- Multi-stage Dockerfile with BuildKit npm cache mounts and a separate
  prod-deps stage so source edits don't reinstall or prune.
- Tighter .dockerignore to shrink build context.
- Healthchecks: add start_period and tighten interval/retries so
  containers report healthy as soon as the process is actually ready
  instead of after a full polling interval.
- Move recoverStuckPreparing() off the startup critical path; the
  recovery sweep now runs in the background after app.listen.
- depends_on uses condition: service_healthy and the obsolete
  compose 'version' key is gone.
- New scripts/build.sh + scripts/deploy.sh: deploy.sh builds, exits
  early if the image is unchanged, runs a blue/green streamer swap
  (scale to 2N, wait healthy in parallel, drop olds), then recreates
  the API with --no-deps to avoid compose's depends_on re-poll.
2026-05-06 13:38:19 +03:00

41 lines
1.2 KiB
Docker

# syntax=docker/dockerfile:1.7
# Stage 1: install all deps (with cache mount so npm cache survives across builds)
FROM node:21-slim AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci --prefer-offline --no-audit --fund=false
# Stage 2: build TypeScript + gulp assets. Source changes only invalidate from here.
FROM node:21-slim AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY package.json package-lock.json tsconfig.json gulpfile.js ./
COPY public ./public
COPY src ./src
RUN npm run build
# Stage 3: prod-only deps. Independent of source so it caches well.
FROM node:21-slim AS prod-deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci --omit=dev --prefer-offline --no-audit --fund=false && \
npm cache clean --force
# Stage 4: minimal runtime
FROM node:21-alpine AS runtime
ENV NODE_ENV=production
ENV PORT=5000
EXPOSE 5000
WORKDIR /app
COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=build /app/build ./build
COPY --from=build /app/public ./public
COPY package.json ./package.json
COPY healthcheck.js ./healthcheck.js
CMD ["node", "./build/server/index.js"]