|
| 1 | +# syntax=docker/dockerfile:1.4 |
| 2 | +# ============================================================================= |
1 | 3 | # Multi-stage Dockerfile for Next.js webapp in monorepo |
| 4 | +# ============================================================================= |
| 5 | +# Industry-standard build with: |
| 6 | +# - BuildKit cache mounts for fast dependency installs |
| 7 | +# - Proper layer ordering for maximum cache hits |
| 8 | +# - Minimal production image |
| 9 | +# |
2 | 10 | # Build context should be monorepo root (../../) |
| 11 | +# ============================================================================= |
3 | 12 |
|
4 | 13 | # ============================================================================ |
5 | 14 | # Stage 1: Base - Common setup |
@@ -34,13 +43,11 @@ COPY packages/extension-indent/package.json ./packages/extension-indent/ |
34 | 43 | COPY packages/extension-inline-code/package.json ./packages/extension-inline-code/ |
35 | 44 | COPY packages/webapp/package.json ./packages/webapp/ |
36 | 45 |
|
37 | | -# Install all dependencies including devDependencies (needed for build) |
38 | | -# Skip Cypress binary download to save time and network (environment variable) |
39 | | -# Cypress package will be installed but won't download browser binaries |
40 | | -# Note: This is only for build stage - final image excludes all node_modules anyway |
41 | | -# Bun handles workspaces automatically |
| 46 | +# Install all dependencies with BuildKit cache mount |
| 47 | +# Skip Cypress binary download to save time and network |
42 | 48 | ENV CYPRESS_INSTALL_BINARY=0 |
43 | | -RUN bun install --verbose |
| 49 | +RUN --mount=type=cache,target=/root/.bun/install/cache \ |
| 50 | + bun install --frozen-lockfile |
44 | 51 |
|
45 | 52 | # ============================================================================ |
46 | 53 | # Stage 3: Build Extensions - Build extension packages first |
@@ -121,10 +128,11 @@ COPY packages/eslint-config ./packages/eslint-config |
121 | 128 | COPY .prettierrc.json ./ |
122 | 129 | COPY tsconfig.json ./ |
123 | 130 |
|
124 | | -# Build Next.js app (standalone output configured in next.config.js) |
| 131 | +# Build Next.js app with cache mount for faster rebuilds |
125 | 132 | # Use build:ci (no dotenv dependency - env vars already set via ARG/ENV) |
126 | 133 | WORKDIR /app/packages/webapp |
127 | | -RUN bun run build:ci |
| 134 | +RUN --mount=type=cache,target=/app/packages/webapp/.next/cache \ |
| 135 | + bun run build:ci |
128 | 136 |
|
129 | 137 | # ============================================================================ |
130 | 138 | # Stage 5: Runner - Production runtime |
|
0 commit comments