fix(Dockerfile.server): only install server workspace dependencies#940
Open
waspeer wants to merge 3 commits intoslopus:mainfrom
Open
fix(Dockerfile.server): only install server workspace dependencies#940waspeer wants to merge 3 commits intoslopus:mainfrom
waspeer wants to merge 3 commits intoslopus:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Dockerfile.servercurrently copies every workspace'spackage.jsonbefore runningyarn install, which causes yarn to resolve and install dependencies for all workspaces — includinghappy-appwith 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_modulesdirectory is large enough to cause the Docker build to OOM-kill during theCOPY --from=builder /repo/node_modulesstep 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 runningyarn install.Fix
Replace non-server workspace
package.jsonfiles with minimal stubs ({"name":"…","version":"0.0.0","private":true}) beforeyarn install, so onlyhappy-serverandhappy-wiredependencies are installed.Additional improvements bundled in:
node:20-slim(smaller base image, no bloat)--frozen-lockfile— the stubs change the effective dependency set, which causes a spurious lockfile mismatch errorffmpegfrom the builder stage (only needed at runtime)node_modules/.bin/tsxdirectly instead ofyarn --cwd … startto avoid yarn process overhead at container startupTesting
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.