perf: optimize Docker build with layer caching and BuildKit support

This commit is contained in:
2025-10-22 23:13:09 -04:00
parent 58bd57543b
commit c030f91ebe
11 changed files with 172 additions and 36 deletions
+10 -6
View File
@@ -4,17 +4,21 @@
FROM node:20-bullseye AS builder
WORKDIR /app
# Install dependencies
# Copy ONLY package files first (creates cacheable layer)
COPY package*.json ./
RUN npm ci
# Copy sources
# Install dependencies with cache mount for faster rebuilds
RUN --mount=type=cache,target=/root/.npm \
npm ci
# Copy source files AFTER npm install (only invalidates cache if code changes)
COPY . .
# Build Angular app (outputs to ./dist)
RUN npx ng build --configuration=production
# Build Angular app with cache mount for Angular's build cache
RUN --mount=type=cache,target=/app/.angular/cache \
npx ng build --configuration=production
# Prune dev dependencies to keep only production deps for runtime copy
# Prune dev dependencies to keep only production deps
RUN npm prune --omit=dev
# -------------------- Runtime stage --------------------