The runtime stage copied the whole production node_modules (495 MB, with
shadcn's CLI tree, the SWC compiler and sharp) and all of .next (163 MB, 119 MB
of it Turbopack's build cache). The image is now 427 MB instead of 1.04 GB:
- Next.js standalone output (NEXT_OUTPUT=standalone, set by the Dockerfile; a
local `next build`/`next start` is unchanged): server.js with only the traced
node_modules (39 MB). images.unoptimized (nothing uses next/image) keeps sharp
and libvips out of the server's trace; /_next/image answers 404.
- build:worker bundles drizzle-orm, zod and ulid into dist/*.mjs and keeps only
@libsql/client and libsql external; the standalone node_modules has both.
- npm's cache and .next/cache are BuildKit cache mounts: reused by the next
build on the same machine (Next build 30 s -> 12 s after a code change), never
in a layer.
- Release archives (BetterBench, both L80 tarballs) are fetched in their own
stage; only the L80 binary is copied, BetterBench is installed from a bind
mount.
- shadcn and tw-animate-css (CSS imports, build time only) move to
devDependencies; package-lock.json regenerated with npm 11 (the image's npm).
Verified by building the image and running web, worker and sandbox from it:
pages and /api/live answer, the worker migrates, takes the lease and finds hf,
BetterBench and L80, all three healthchecks pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EooZ9biu7kFNB4eDJrwQc5