Skip to content

fix(Dockerfile.server): only install server workspace dependencies#940

Open
waspeer wants to merge 3 commits intoslopus:mainfrom
waspeer:fix/server-dockerfile-slim-deps
Open

fix(Dockerfile.server): only install server workspace dependencies#940
waspeer wants to merge 3 commits intoslopus:mainfrom
waspeer:fix/server-dockerfile-slim-deps

Conversation

@waspeer
Copy link
Copy Markdown

@waspeer waspeer commented Mar 30, 2026

Problem

Dockerfile.server currently copies every workspace's package.json before running yarn install, which causes yarn to resolve and install dependencies for all workspaces — including happy-app with its 140+ React Native / Expo / livekit packages.

This is only needed for the mobile app, never for the server. On a typical VPS (3–4 GB RAM) the resulting node_modules directory is large enough to cause the Docker build to OOM-kill during the COPY --from=builder /repo/node_modules step in the runner stage.

Root cause

Yarn 1 (classic) does not support yarn workspaces focus (that was introduced in yarn 2/berry). The only yarn-1 workaround is to stub out the workspaces you don't need before running yarn install.

Fix

Replace non-server workspace package.json files with minimal stubs ({"name":"…","version":"0.0.0","private":true}) before yarn install, so only happy-server and happy-wire dependencies are installed.

Additional improvements bundled in:

  • Switch to node:20-slim (smaller base image, no bloat)
  • Drop --frozen-lockfile — the stubs change the effective dependency set, which causes a spurious lockfile mismatch error
  • Remove ffmpeg from the builder stage (only needed at runtime)
  • Use node_modules/.bin/tsx directly instead of yarn --cwd … start to avoid yarn process overhead at container startup

Testing

Verified locally on a 3.7 GB RAM VPS: the slim build completes in ~3 minutes without hitting memory limits, whereas the original Dockerfile OOM-killed the build even with 4 GB of swap added.

waspeer added 3 commits March 30, 2026 09:54
yarn 1 (classic) has no `workspaces focus` command, so by default it
installs every workspace's dependencies. happy-app alone pulls in 140+
React Native / Expo / livekit packages that are never needed at runtime
for the server. On a typical VPS (3-4 GB RAM) this causes the Docker
build to OOM when copying node_modules into the runner stage.

Fix: replace non-server workspace package.json files with minimal stubs
(name + version only) before running yarn install, so only happy-server
and happy-wire dependencies are installed.

Other changes:
- Switch to node:20-slim to reduce image size
- Drop --frozen-lockfile (stubs change the effective dep set, causing a
  false lockfile mismatch)
- Remove ffmpeg from the builder stage (only needed at runtime)
- Use node_modules/.bin/tsx directly instead of `yarn --cwd ... start`
  to avoid yarn overhead at container startup
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