Why this matters
Reduces maintenance overhead and prevents divergent build behavior between services.
Deduplicate near-identical Dockerfiles by sharing a common base stage (multi-stage) and varying only service-specific steps via build args/targets.
Reduces maintenance overhead and prevents divergent build behavior between services.
Side-by-side examples engineers can pattern-match during review.
# api/Dockerfile and worker/Dockerfile copy-pasted with minor changesFROM node:20.11.1-alpine AS base
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
FROM base AS build
COPY . .
RUN npm run build
# Select service at build time
ARG SERVICE
FROM gcr.io/distroless/nodejs20 AS runtime
WORKDIR /app
COPY --from=build /app/services/${SERVICE}/dist ./
CMD ["server.js"]# Two Dockerfiles differing only in CMDARG SERVICE && multi-stage targets share a common baseFrom the same buckets as this rule.