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 <noreply@anthropic.com>
This commit is contained in:
@@ -10,3 +10,8 @@ docs/
|
||||
legacy/
|
||||
dwg2dxf-api/
|
||||
.DS_Store
|
||||
.claude/
|
||||
.vscode/
|
||||
.idea/
|
||||
*.log
|
||||
*.tsbuildinfo
|
||||
|
||||
+11
-8
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user