From f5d2f4cac28c24bae6b18a1c0053baa04eb84ef4 Mon Sep 17 00:00:00 2001 From: Jake Bromberg Date: Fri, 13 Feb 2026 20:50:57 -0800 Subject: [PATCH] ci: fix Docker builder-stage layer caching Both Dockerfiles copied source code before npm install in the builder stage, invalidating the dependency cache on every code change. Restructure to copy package manifests first, run npm ci (deterministic), then copy source and build. This enables Docker layer caching for the npm ci step when only source code changes (the common case). --- Dockerfile.auth | 12 ++++++++++-- Dockerfile.backend | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Dockerfile.auth b/Dockerfile.auth index 1095cb22..7d79aa80 100644 --- a/Dockerfile.auth +++ b/Dockerfile.auth @@ -3,12 +3,20 @@ FROM node:22-alpine AS builder WORKDIR /auth-builder -COPY ./package.json ./ +# Copy package manifests first for better layer caching +COPY ./package.json ./package-lock.json ./ +COPY ./apps/auth/package.json ./apps/auth/ +COPY ./shared/database/package.json ./shared/database/ +COPY ./shared/authentication/package.json ./shared/authentication/ + +RUN npm ci + +# Copy source code and build (this layer invalidates on code changes) COPY ./tsconfig.base.json ./ COPY ./shared ./shared COPY ./apps/auth ./apps/auth -RUN npm install && npm run build --workspace=@wxyc/database --workspace=shared/** --workspace=@wxyc/auth-service +RUN npm run build --workspace=@wxyc/database --workspace=shared/** --workspace=@wxyc/auth-service #Production stage FROM node:22-alpine AS prod diff --git a/Dockerfile.backend b/Dockerfile.backend index a31baec3..57e5e8a7 100644 --- a/Dockerfile.backend +++ b/Dockerfile.backend @@ -3,12 +3,20 @@ FROM node:22-alpine AS builder WORKDIR /builder -COPY ./package.json ./ +# Copy package manifests first for better layer caching +COPY ./package.json ./package-lock.json ./ +COPY ./apps/backend/package.json ./apps/backend/ +COPY ./shared/database/package.json ./shared/database/ +COPY ./shared/authentication/package.json ./shared/authentication/ + +RUN npm ci + +# Copy source code and build (this layer invalidates on code changes) COPY ./tsconfig.base.json ./ COPY ./shared ./shared COPY ./apps/backend ./apps/backend -RUN npm install && npm run build --workspace=@wxyc/database --workspace=shared/** --workspace=@wxyc/backend +RUN npm run build --workspace=@wxyc/database --workspace=shared/** --workspace=@wxyc/backend #Production stage FROM node:22-alpine AS prod