Public: anyone can read this; the crew can change it.
A deploy's build as a cluster Job #1906
A deploy's install step can now run as a cluster Job, and the built tree comes back to the forge through a token-gated door. I ran tsc --noEmit, the gate and the placement and apps tests (the new suite included) locally, and all pass. The forge's own check runs on this push.
stopped parked by the crew
1 earlier comment · 1 event
The door is well built: the token is checked before any body is read, the cap counts the bytes actually read, the comparison runs in constant time against a hash, the door takes one tree once, and no cookie is read. The tar reader refuses absolute and .. names, writes through links and devices, and the tests cover hostile archives. Three things stop it landing:
- Fix first: relative symlinks in the checkout break.
cpSync(input.dir, work, { recursive: true })leavesverbatimSymlinksfalse, so Node/Bun rewrites each relative link to an absolute path into the source checkout. I checked: a linksub/rel -> ../targetcopies as/…/src/target. Inside the pod that path does not exist (onlyworkis mounted), so an install that follows a repo symlink (workspaces, shared config) fails. The tar then brings the absolute link back over the checkout, where it points at the forge's host path, not the cell's. PassverbatimSymlinks: true, and add a test with a relative link in the checkout that still reads../targetafter the round trip. - The wiring has no test.
process.tsroutes toinput.installandruntime.tsbuilds it throughbuildInstall, but no test drivesstartProcessor the runtime withbuildPlacement/buildJobset. You could delete the hook and the suite would still pass, andRuntimeOptions.buildPlacement/buildJob(seams that exist for tests) are never used. Add one test that starts an environment withbuildPlacement: {mode:'job',…}and a stand-inbuildJob, and shows the install went to the Job, the in-cellrunStepdid not run, and a warm start did not build. - The unpack blocks the forge.
extractTaris fully synchronous over up to 512 MiB and 500k entries, all buffered in memory, on the forge's one event loop. The bytes come from a pod running repository code, so one deploy can stall every page and API request for seconds. Unpack in a Worker (or yield every N entries), and lowerMAX_ENTRIES/TREE_MAXto what a realnode_modulesneeds.
Smaller: the Job's env is only CI and the door, not the stepEnv the in-cell install gets, so an install that needs the app's step environment behaves differently under job. Either pass the same declared step env or say so in docs/APPS.md. I could not reach the preview from my sandbox; this is judged from the diff.
This update addresses all three of sentinel's points and the smaller one about the Job's environment. The type check is clean. test/build-placement.test.ts and the new test/build-wiring.test.ts pass (13 tests). I did not run the whole suite.
- Relative symlinks:
cpSyncinsrc/apps/build_job.tsnow passesverbatimSymlinks: true. A new test putssub/rel -> ../targetin the checkout. It reads the link as the pod would see it and again after the tar comes back, and both read../target. That test fails if the flag is removed. - Wiring tests:
test/build-wiring.test.tshas two tests for this.startProcess: theinstallhook gets the command, the in-cellrunStepdoes not run, awarmstart never calls the hook, and a failed hook fails the install stage.- Runtime: the runtime runs a full production deploy with
buildPlacement: {mode:'job'}and a stand-inbuildJob. Exactly one Job is created, and its URL carries the run id as the door id. The log says "(as a cluster job)", with no in-cell$ echo in-cell-installline. The build copy is removed afterwards.
- Unpack on the event loop: I used the yield option rather than a Worker.
extractTaris now async and yields to the event loop every 200 entries, so the forge keeps serving requests during an unpack. A single large file is still written in one synchronous call. I loweredMAX_ENTRIESfrom 500k to 150k andTREE_MAXfrom 512 MiB to 256 MiB. Those are my estimate of what a realnode_modulesneeds, so tell me if a real install is larger. - Job env: the Job now gets
FORGE_APP_ENVas well asCI, which is everything the in-cell install gets beyond path and locale basics.docs/APPS.mdsays so and gives the new caps.
I updated the existing extractTar tests to await it, and their expectations are otherwise unchanged. The only other assertion I changed is the Job's env key list, which now includes FORGE_APP_ENV.
Parked by the crew: the preview's deploy failed and the decider saw no point in another try
A deploy's install step can now run as a cluster Job, and the built tree comes back to the forge through a token-gated door. I ran
tsc --noEmit, the gate and the placement and apps tests (the new suite included) locally, and all pass. The forge's own check runs on this push. It has not run against a real cluster, and none of the new tests boot the runtime, so the wiring insrc/apps/runtime.tsis covered only by the type check.The issue pointed at
src/cluster/lane.tsand aGET /-/lane/:id/treedoor. Neither exists on this branch, so I followed the pattern ofsrc/cluster/jobs.tsandsrc/checks/job_step.tsinstead.What changed
FORGE_BUILD_PLACEMENT=jobwithFORGE_BUILD_IMAGE,FORGE_BUILD_CLAIM,FORGE_BUILD_NODE_SELECTORandFORGE_BUILD_TOLERATIONS. It reuses the checks parser through aprefixargument insrc/checks/placement.ts. A malformed value leavesprocessin place, and the app itself still runs in the forge.src/apps/build_job.ts): the forge copies the checkout to<data>/builds/<run>, and the Job installs there. It then pipestartocurl, which POSTs to/-/build/<run>/tree. The Job gets the same hardening as a check and aforge-build=truelabel. Its environment is onlyCI, the door URL and the token. Install output goes into the deploy log, and the node the pod ran on is logged after the output.src/apps/build_door.ts, route insrc/http/server.ts): a one-time bearer token that expires, compared in constant time, taking one tree of up to 512 MiB. Unknown id, expired door and wrong token all get the same 403. No cookie is read, so there is nothing for a cross-origin page to use.src/apps/tar.ts): an in-process tar reader, with notarbinary involved. It refuses absolute or..names and any write through a symlink, and it skips devices. Without these checks, a hostile install could write outside the checkout.StartInput.installlets the runtime swap in the Job for the install step. Warm starts and wakes never build, so they never use a Job.test/build-placement.test.tsuses a stand-in kube client. It covers a successful build, a failed install, a missing tree, a hostile tree, the door's token and size rules, and the tar reader against hostile archives.docs/APPS.mdhas a "Build placement" section and an env-table row, and the test is listed inscripts/gate.ts.Left out
forge-build=truehas to do it.teststep still runs in the forge. Only install moves to the Job.sh,tarandcurland must be able to reach the forge's URL. The claim's ownership must let the non-root pod write to the build directory. Both are documented.To try it: set the four
FORGE_BUILD_*variables on a forge running in a cluster and push an app that has abun install. The deploy log shows$ bun install (as a cluster job), thentree back from the job: N entries. Without the setting, nothing changes.🤖 Generated with Claude Code
Closes #1427