Repository navigation
deploy: add staged server bundle to shrink the GAE install - #809
Conversation
`pnpm deploy:web` deploys from the workspace root, so App Engine's buildpack reinstalls every workspace package's dependency closure on the instance (~590 MB / 1171 packages) -- React, slate, radix, rspress, vite, jest -- none of which the server needs at runtime. App Engine standard always reinstalls from the deployed package.json + lockfile and has no vendored-node_modules escape hatch, so the only lever is the deployed manifest; the pnpm10 devDep bug is secondary, since the dominant cost is installing the whole workspace at all. Add `pnpm deploy:web:staged`, which assembles a self-contained deploy-staging/ whose package.json is exactly the server's prod closure (~80 MB / 230 packages) and deploys that. The two unpublished workspace packages (@simlin/core, @simlin/engine) are vendored and referenced via file: deps, since a registry install would 404 on them; core's transitive @simlin/engine ref is rewritten too. A pnpm-lock.yaml is generated for the minimal manifest with peer settings pinned so the lockfile does not depend on the operator's ambient .npmrc. The pure transforms (scripts/deploy-staging-manifests.mjs) are unit-tested via pnpm test:scripts; the builder self-verifies the artifact (full wasm with the simlin_project_render_png export, substituted index.html, no residual workspace: refs) and guards against an app.yaml entrypoint that would not resolve in the flat staging layout. Proven locally end to end: an isolated frozen-lockfile install boots the server and serves /, the embed component, and static assets. deploy:web stays the default and fallback until a real gcloud --no-promote test confirms the nodejs24 buildpack accepts the result.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27c9063ffb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| 'install', | ||
| '--lockfile-only', | ||
| '--ignore-workspace', |
There was a problem hiding this comment.
Preserve checked-in pins for staged deploys
In staged deploys this runs in a freshly deleted deploy-staging/ and no committed root pnpm-lock.yaml is copied; I checked pnpm install --help, where --ignore-workspace treats the install as a normal non-workspace install and --lockfile-only only writes the lockfile. That means pnpm deploy:web:staged resolves the semver ranges in the generated package.json against the registry at deploy time, while the build/tests just ran against the checked-in workspace lockfile, so a new compatible direct or transitive release can be deployed untested even with a frozen install on GAE. Please derive the staged lock from the committed lockfile, or otherwise pin the same versions, before deploying.
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #809 +/- ##
==========================================
- Coverage 90.87% 90.87% -0.01%
==========================================
Files 224 224
Lines 143133 143133
==========================================
- Hits 130072 130071 -1
- Misses 13061 13062 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code Review: Reviewed scope: scripts/build-deploy-staging.mjs, scripts/deploy-staging-manifests.mjs, scripts/deploy-web-staged.sh, scripts/tests/deploy-staging-manifests.test.mjs, docs/package.json wiring. No actionable bugs identified. The pure transforms in deploy-staging-manifests.mjs are well-isolated and thoroughly tested (peer-dep rejection, optional-dep handling, no-mutation invariants, unknown-workspace-dep failure). The build script has appropriate fail-loud guards: missing source artifacts, the entrypoint compatibility check (correctly handles trailing whitespace via the non-greedy capture + trim pattern), the wasm export check (catches accidental shipping of the slim browser wasm), and the residual-workspace-protocol assertions in both build and verify paths. The flat layout (lib/ at staging root) is consistent across the package.json start script, the assertCompatibleEntrypoint guard, and the wasm.node.ts __dirname resolution. The two unpublished workspace packages are correctly vendored with their transitive workspace refs rewritten to file:../ siblings, and the files field is dropped to prevent the inherited list from masking the deliberately-minimal vendor contents. Overall correctness verdict: correct. The patch is additive (new scripts, npm scripts, doc/tech-debt updates), keeps deploy:web as the proven fallback per the PR description, and has been verified end-to-end locally against an isolated install simulating the GAE environment. The remaining unknown (whether the nodejs24 buildpack honors corepack + the frozen lockfile) is explicitly called out and gated on a real --no-promote test before flipping the default. |
The staged deploy generated its pnpm-lock.yaml in a freshly deleted dir with no lockfile seed, so `pnpm install --lockfile-only` re-resolved the semver ranges against the registry at deploy time. The build and tests run against the committed root lockfile, so a newer compatible release (direct or transitive) could be deployed untested -- even though GAE then does a frozen install, because that frozen lockfile was itself resolved fresh. Flagged by Codex review on #809. Seed the staging lockfile from the committed root pnpm-lock.yaml: copy its packages/snapshots resolution cache with the importers dropped, so pnpm reuses the already-locked, CI-tested versions and resolves only the new file: vendored packages, then prunes to the staging closure. Dropping importers is what triggers the prune; keeping them balloons the lockfile back to the whole-workspace closure. A downgrade test confirmed the seed pins (a seeded [email protected] is kept, not bumped to the newest 8.2.0). A post-generation guard (untestedPackages) fails the build if any registry version in the staging lockfile is absent from the root lockfile -- the explicit guarantee that the deploy only ships versions the workspace install actually resolved and tested.
|
Addressed the Codex P2 (lockfile re-resolution) in 66b8ffe. The staging |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 66b8ffe6b9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /src/app/build | ||
| /src/app/build-component | ||
| /src/app/test-results | ||
| /deploy-staging |
There was a problem hiding this comment.
Exclude deploy-staging from root gcloud uploads
Adding deploy-staging only to .gitignore does not protect the fallback deploy path: the root .gcloudignore explicitly does not import .gitignore, and deploy-web-staged.sh intentionally leaves this directory behind for inspection. After a pnpm deploy:web:staged --no-promote smoke test, a subsequent fallback pnpm deploy:web from the repo root will upload the whole staged artifact (including the copied app.yaml, vendor packages, lockfile, and public bundle) unless /deploy-staging/ is also ignored by the root .gcloudignore or the staged directory is removed during cleanup.
Useful? React with 👍 / 👎.
deploy-web-staged.sh leaves deploy-staging/ in place after a staged deploy so a --no-promote smoke test can inspect it, and the .gitignore entry keeps it out of git -- but the root .gcloudignore deliberately does NOT import .gitignore (so gitignored build output like src/*/lib still uploads). So a subsequent fallback `pnpm deploy:web`, which uploads from the repo root, would sweep the ~28 MB leftover staged artifact into the upload -- including a copy of app.yaml carrying the session secret -- and eat into GAE's 10k-file budget. Exclude /deploy-staging/ in the root .gcloudignore. The staged deploy uploads from deploy-staging/ with its own .gcloudignore, so this entry is inert for it. Flagged by Codex review on #809.
|
Addressed in the latest commit: @codex review |
ReviewReviewed all 8 files: the two new scripts, the test file, the shell driver, and the doc / FindingsNo actionable bugs identified. The change is well-scoped and defensively constructed:
Minor observations that are below the threshold for flagging individually:
Overall correctness verdictCorrect. The changes are additive (new script + new |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Reviewed the PR end-to-end (manifest transforms, lockfile seeding/pruning logic, A few minor observations (not blocking):
Overall correctness: correct. |
Why
pnpm deploy:webrunsgcloud app deployfrom the workspace root, so the App Engine instance'spnpm installwalkspnpm-workspace.yamland installs every workspace package's dependency closure — React, slate, radix, rspress, vite, jest,@rsbuild/*— ~590 MB / 1171 packages, none of which the Express server needs at runtime.App Engine standard always reinstalls from the deployed
package.json+ lockfile and has no vendored-node_modulesescape hatch (confirmed against Google's docs), so the only lever that shrinks the install is the deployed manifest. The pnpm10NODE_ENV=productiondevDep bug (buildpacks#591) is secondary: even a perfect--prodinstall of the whole workspace would still pull React/slate/radix/rspress/vite, because those are runtime deps of other packages. The real cost is installing the whole workspace at all.What
Adds
pnpm deploy:web:staged, which deploys from a self-containeddeploy-staging/whosepackage.jsonis exactly the server's prod closure — ~80 MB / 230 packages.deploy:web(today)deploy:web:stagedHow it works
scripts/deploy-web-staged.shmirrorsdeploy-web.sh(validate → clean → build →deploy:assemble→verify-deploy-build.sh), then runsscripts/build-deploy-staging.mjsandgcloud app deploy deploy-staging/app.yaml.@simlin/coreand@simlin/engineare not published to npm, so apnpm deployversion-rewrite (workspace:*→2.0.0) would 404 on the instance. Instead they are vendored intodeploy-staging/vendor/and referenced viafile:deps; core's transitive@simlin/engineref is rewritten too. The wasm keeps loading unchanged (the engine stays a real package dir;wasm.node.jsresolvescore/libsimlin.wasmvia__dirname).libsimlin.wasmis vendored; the browser variants are deliberately omitted (plain Noderequirenever selects themodule/browser export condition), keeping the 4.8 MB slim wasm off the server image.pnpm-lock.yamlis generated for the minimal manifest with peer settings pinned (--config.auto-install-peers=true --config.strict-peer-dependencies=false) so the lockfile doesn't depend on the operator's ambient.npmrc.scripts/deploy-staging-manifests.mjs(unit-tested viapnpm test:scripts); the builder self-verifies the artifact (full wasm withsimlin_project_render_png, substitutedindex.html, no residualworkspace:refs) and guards against anapp.yamlentrypointthat wouldn't resolve in the flat layout. Unknown workspace deps andpeerDependenciesfail loud rather than ship a broken manifest.Testing (local, end-to-end)
pnpm test:scripts: 33 unit tests green.pnpm install --frozen-lockfile --prodin a copy outside the repo (no workspace/.npmrcancestor) installs cleanly from the generated lockfile (74–80 MB / 230 pkgs); the full wasm materializes at the__dirnamepath; all serverrequires (incl.@simlin/core/common) resolve.node lib/index.jsboots (WASM module initialized successfully) and serves/→ 200,/api/user→ 401,/static/js/sd-component.js→ 200,/robots.txt→ 200.Not yet verified / why
deploy:webstays the defaultThe literal
gcloud app deployupload and the nodejs24 buildpack behavior can't be tested locally: whether it honorspackageManager: [email protected]via corepack and accepts the frozenlockfileVersion. Runpnpm deploy:web:staged --no-promote, confirm the instance ran a successful frozenpnpm install, then the post-deploy smoke test — before this replacesdeploy:web.deploy:webremains the proven fallback (untouched).Relates to tech-debt #39 (and incidentally puts the upload well under GAE's 10k-file cap, #695, once this becomes the default).