Skip to content

improvement(docker): speed up app image build with cache mounts and parallel node-gyp#4310

Merged
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/dockerfile-speedups
Apr 27, 2026
Merged

improvement(docker): speed up app image build with cache mounts and parallel node-gyp#4310
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/dockerfile-speedups

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Add .next/cache and .turbo BuildKit cache mounts on bun run build (per-platform id= to isolate arm64/amd64 SWC artifacts)
  • Cap node-gyp rebuild of isolated-vm at JOBS=4 (higher values OOM per isolated-vm does not build on small machines laverdet/isolated-vm#428)
  • Remove redundant bun install sharp step — sharp is already a regular dep, the second install just busts cache on every source change

Type of Change

  • Improvement

Testing

Tested manually — diff is local to docker/app.Dockerfile; will verify cold/warm ARM64 build times on first deploy after merge. Target: ~7–8 min cold, ~3–4 min warm (down from 11–12/6–7).

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 27, 2026 8:15pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 27, 2026

PR Summary

Low Risk
Low risk since changes are confined to docker/app.Dockerfile build steps, though they could affect Docker build performance/correctness if cache mounts or TARGETPLATFORM handling behave unexpectedly in CI.

Overview
Speeds up docker/app.Dockerfile builds by adding BuildKit cache mounts for Next.js (.next/cache) and Turbo (.turbo) during bun run build, using per-platform cache IDs via TARGETPLATFORM to avoid cross-arch artifact pollution.

Caps isolated-vm rebuild parallelism (JOBS=4) to prevent OOMs, and removes the redundant bun install sharp step that was busting the build cache.

Reviewed by Cursor Bugbot for commit 60ee87d. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR speeds up the Docker app image build by adding BuildKit cache mounts for the Next.js compiler cache (.next/cache) and Turbo task cache (.turbo) — correctly scoped per-platform so arm64 and amd64 SWC artifacts stay isolated — capping node-gyp parallelism at JOBS=4 to prevent OOM during isolated-vm compilation, and removing the redundant bun install sharp step that was invalidating cache on every source change. The sharp removal is safe: the project uses sharp 0.34.3, which ships prebuilt binaries via optionalDependencies (no lifecycle scripts needed), so they are already present after the root-level bun install.

Confidence Score: 5/5

Safe to merge — changes are purely build-time optimizations with no runtime behavior impact.

All three changes are sound: JOBS=4 is a well-documented fix for the isolated-vm OOM issue, per-platform cache IDs correctly isolate SWC artifacts, and removing the bun install sharp is safe since sharp 0.34.3 distributes platform binaries as optionalDependencies (no postinstall scripts required). WORKDIR context is preserved correctly after the sharp step removal.

No files require special attention.

Important Files Changed

Filename Overview
docker/app.Dockerfile Three targeted optimizations: JOBS=4 cap on node-gyp, per-platform BuildKit cache mounts for .next/cache and .turbo, and removal of redundant bun install sharp (safe since sharp 0.34.3 uses optionalDependencies for platform binaries, no lifecycle scripts needed).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["FROM base AS deps"] --> B["bun install --omit=dev --ignore-scripts --linker=hoisted\n(bun-cache + npm-cache mounts, no platform suffix)"]
    B --> C["JOBS=4 npx node-gyp rebuild --release\n(isolated-vm native addon)"]

    D["FROM base AS builder\nARG TARGETPLATFORM"] --> E["bun install -g turbo\n(bun-cache mount)"]
    E --> F["COPY node_modules from deps"]
    F --> G["COPY source code"]
    G --> H["bun run build\n--mount next-cache-TARGETPLATFORM\n--mount turbo-cache-TARGETPLATFORM"]

    C --> F
    H --> I["FROM base AS runner"]
    I --> J["COPY .next/standalone\n+ isolated-vm from deps\n+ static assets"]
    J --> K["CMD bun apps/sim/server.js"]
Loading

Reviews (1): Last reviewed commit: "improvement(docker): speed up app image ..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant