Optimize Docker build caching and slim image

- Add pnpm store cache mount so package reuse survives layer invalidation
- Copy only prisma schema files (not migrations/programmability/seed) into deps
- Remove prisma and scripts from runner stage (no longer running migrations in container)
- Expand .dockerignore to exclude docs, tests, .claude, .github, .vscode (~30MB less context)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Justin Maier
2026-04-03 11:17:26 -06:00
parent 55af6349f4
commit 1b6cd6bc75
2 changed files with 19 additions and 12 deletions
+10 -1
View File
@@ -7,4 +7,13 @@ nginx
.git
.gitignore
.next
.dockerignore
.dockerignore
docs
tests
.claude
.github
.vscode
playwright.config.ts
prisma/migrations
prisma/programmability
prisma/seed.ts
+9 -11
View File
@@ -7,18 +7,18 @@ WORKDIR /app
# Enable corepack for pnpm
RUN corepack enable && corepack prepare pnpm@10.28.1 --activate
# Install Prisma Client - remove if not using Prisma
# Copy Prisma schemas for client generation (postinstall runs prisma generate)
COPY prisma/schema.full.prisma prisma/schema.prisma ./prisma/
COPY prisma ./prisma
# Install dependencies
COPY package.json pnpm-lock.yaml ./
# copy ./scripts directory to /app/scripts to run prisma enum generator
# Install dependencies — lockfile and scripts rarely change, so they go first.
# package.json changes on every version bump but pnpm only needs it for the
# workspace root name; the store cache mount lets pnpm reuse downloaded packages
# even when this layer is invalidated.
COPY pnpm-lock.yaml package.json ./
COPY scripts ./scripts
RUN pnpm install --frozen-lockfile
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile
##### BUILDER
@@ -56,8 +56,6 @@ RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/scripts ./scripts
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static