@@ -10,14 +10,15 @@ FROM base AS deps
1010RUN apk add --no-cache libc6-compat
1111WORKDIR /app
1212
13- # Install turbo globally
13+ # Install turbo globally (cached separately, changes infrequently)
1414RUN bun install -g turbo
1515
1616COPY package.json bun.lock turbo.json ./
1717RUN mkdir -p apps packages/db
1818COPY apps/sim/package.json ./apps/sim/package.json
1919COPY packages/db/package.json ./packages/db/package.json
2020
21+ # Install dependencies (this layer will be cached if package files don't change)
2122RUN bun install --omit dev --ignore-scripts
2223
2324# ========================================
@@ -26,14 +27,26 @@ RUN bun install --omit dev --ignore-scripts
2627FROM base AS builder
2728WORKDIR /app
2829
29- # Install turbo globally in builder stage
30+ # Install turbo globally (cached separately, changes infrequently)
3031RUN bun install -g turbo
3132
33+ # Copy node_modules from deps stage (cached if dependencies don't change)
3234COPY --from=deps /app/node_modules ./node_modules
33- COPY . .
3435
35- # Installing with full context to prevent missing dependencies error
36- RUN bun install --omit dev --ignore-scripts
36+ # Copy package configuration files (needed for build)
37+ COPY package.json bun.lock turbo.json ./
38+ COPY apps/sim/package.json ./apps/sim/package.json
39+ COPY packages/db/package.json ./packages/db/package.json
40+
41+ # Copy workspace configuration files (needed for turbo)
42+ COPY apps/sim/next.config.ts ./apps/sim/next.config.ts
43+ COPY apps/sim/tsconfig.json ./apps/sim/tsconfig.json
44+ COPY apps/sim/tailwind.config.ts ./apps/sim/tailwind.config.ts
45+ COPY apps/sim/postcss.config.mjs ./apps/sim/postcss.config.mjs
46+
47+ # Copy source code (changes most frequently - placed last to maximize cache hits)
48+ COPY apps/sim ./apps/sim
49+ COPY packages ./packages
3750
3851# Required for standalone nextjs build
3952WORKDIR /app/apps/sim
@@ -64,15 +77,16 @@ RUN bun run build
6477FROM base AS runner
6578WORKDIR /app
6679
67- # Install Python and dependencies for guardrails PII detection
80+ # Install Python and dependencies for guardrails PII detection (cached separately)
6881RUN apk add --no-cache python3 py3-pip bash
6982
7083ENV NODE_ENV=production
7184
72- # Create non-root user and group
85+ # Create non-root user and group (cached separately)
7386RUN addgroup -g 1001 -S nodejs && \
7487 adduser -S nextjs -u 1001
7588
89+ # Copy application artifacts from builder (these change on every build)
7690COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/public ./apps/sim/public
7791COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/.next/standalone ./
7892COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/.next/static ./apps/sim/.next/static
0 commit comments