From 28bb395b06350c0fffebc7f2cd78798f482755ba Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Wed, 11 Mar 2026 21:15:41 +0200 Subject: [PATCH] perf: optimize Docker build for faster deployments - Move prisma generate before COPY . . so it's cached when only source files change (saves ~10-15s per build) - Use npm ci --ignore-scripts in deps stage (postinstall scripts not needed, prisma generate runs explicitly) - Combine apk add + addgroup + adduser into single RUN (fewer layers) - Expand .dockerignore to exclude .claude/, .vscode/, logs, tsbuildinfo Co-Authored-By: Claude Opus 4.6 --- .dockerignore | 5 +++++ Dockerfile | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index e9a0c55..3518aa9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,3 +10,8 @@ docs/ legacy/ dwg2dxf-api/ .DS_Store +.claude/ +.vscode/ +.idea/ +*.log +*.tsbuildinfo diff --git a/Dockerfile b/Dockerfile index afba611..0c43219 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,17 @@ FROM node:20-alpine AS deps WORKDIR /app COPY package.json package-lock.json ./ -RUN npm ci +RUN npm ci --ignore-scripts FROM node:20-alpine AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules + +# Copy prisma schema first — cached layer for prisma generate +COPY prisma ./prisma +RUN npx prisma generate + +# Now copy the rest of the source COPY . . # Build args for NEXT_PUBLIC_* vars (inlined at build time) @@ -17,9 +23,6 @@ ENV NEXT_PUBLIC_STORAGE_ADAPTER=${NEXT_PUBLIC_STORAGE_ADAPTER} ENV NEXT_PUBLIC_APP_NAME=${NEXT_PUBLIC_APP_NAME} ENV NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL} -# Generate Prisma client before building -RUN npx prisma generate - RUN npm run build FROM node:20-alpine AS runner @@ -27,13 +30,13 @@ WORKDIR /app ENV NODE_ENV=production -RUN apk add --no-cache gdal gdal-tools ghostscript qpdf +# Install system deps + create user in a single layer +RUN apk add --no-cache gdal gdal-tools ghostscript qpdf \ + && addgroup --system --gid 1001 nodejs \ + && adduser --system --uid 1001 nextjs # Note: DWG→DXF conversion handled by dwg2dxf sidecar container (see docker-compose.yml) -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs - COPY --from=builder /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static