perf: optimize Docker build with layer caching and BuildKit support
This commit is contained in:
+10
-6
@@ -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 --------------------
|
||||
|
||||
Reference in New Issue
Block a user