Repository navigation
Reuse unchanged container images in staging and production deploys - #2770
Conversation
Key each Instant container image by its Dockerfile, copied files and a fingerprint of every network-installed input (apt indexes, fetched URLs, isolated npm resolutions, uv PyPI resolutions). A registry tag inputs-<key> records a built image; an unchanged key deploys that digest with no build, push or rollout. Any doubt leaves the Dockerfile for Wrangler to build as before. Pin the uv installer. Build only the linux VM-agent binaries the deploy publishes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m review Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- rebuild a fresh digest when the latest container rollout failed, was cancelled or cannot be read, so redeploying retries the rollout - allowlist RUN commands and fetched URLs; npm install scripts that run must belong to reviewed packages - resolve PyPI with --no-build --no-config, run resolvers without the deploy secrets, look up the registry with pull-only credentials - verify the uv installer checksum on the runner; cap credential lifetime - split the Docker/registry boundary into container-image-registry.ts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-deploys-stop-cad8ke
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-deploys-stop-cad8ke
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
@coderabbitai review |
Action not completed
|
- Dockerfile.vm-agent-container downloads the pinned uv installer over HTTPS-only redirects, checks its sha256, then runs it (Sonar S8482, S6506); the image analysis allows running a file a RUN downloaded from a reviewed URL, and sha256sum - enforce HTTPS redirects for the runner-side uv installer - explicit code-unit sort comparator (never localeCompare: keys must not depend on the host locale); URL literals stop at shell separators - small readability fixes Sonar flagged Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-deploys-stop-cad8ke
…e; file Artifacts Instant clone race Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|



Summary
Staging and production deploys stop rebuilding, pushing and rolling out the two Instant container images (
apps/api/Dockerfile.sandbox,apps/api/Dockerfile.vm-agent-container) when nothing that goes into them has changed. Task01M7G55K6BSR1RPMZK14CAD8KE; ideas01M7FYGMEESYH3AJZJ0CT3NKCZand01M0QED2G61RWM8Z3TPFCHEQXS(item S1).Measured on staging, same day:
inputs-<key>, rolled outreused; Wrangler: "No changes to be made" for both applicationsbuilt+ rolled out; VM agentreusedProduction baseline: 43749474483 took 21.1 min (Deploy API Worker 408 s, rollout wait 304 s). With unchanged images a production deploy should take about 8 min.
How it works
The new Resolve container images step in
deploy-reusable.ymlruns after the VM-agent artifact is prepared and before the firstwrangler deploy. It runsscripts/deploy/container-image-reuse.ts:analyzeDockerfile()(container-image-inputs.ts) reads every input from the Dockerfile:deblines written inRUN;npm install -gspecs;uv tool installspecs;fingerprintInputs()(container-image-fingerprints.ts) fingerprints each floating input, so the key changes whenever upstream can change the image:InReleaseSHA256 lines for each component's amd64 Packages index. Re-signing alone does not change it.npm install --package-lock-onlyper global package, because global installs do not dedupe across packages.uv pip compile --no-build --no-configper tool.composeImageKey()hashes all of it together with the Dockerfile bytes and Wrangler's build flags. A missing fingerprint throws, so a partial set never produces a key.inputs-<key>lives in the repository Wrangler already uses (<worker>-<class>-<env>) and records an image built from those inputs.docker buildwith Wrangler's flags, pushes under the tag, and deploys the new digest.[env.<env>].containersimage. This is the existingSAM_CONTAINER_IMAGE_OVERRIDESpath; the value is also exported toGITHUB_ENVso the first-install tail re-sync keeps it.image_uriinstead of building.Any doubt leads to a rebuild, never to reuse. In every case below the Dockerfile is left for Wrangler to build, exactly as before:
RUNcommand outsideALLOWED_COMMANDS;REVIEWED_FETCH_URLS;REVIEWED_NPM_INSTALL_SCRIPTS;A failed
docker buildfails the deploy, as Wrangler's would. If the application's latest rollout failed, was cancelled, or cannot be read, the image is rebuilt to a fresh digest, so a redeploy starts a new rollout instead of re-pointing at the failed one.Why not a Docker layer cache (requirement 2)
Measured, and read from the Wrangler 4.149 source (
pushImageIfChanged,apply):RUNlayer on its instruction text, so it would freeze the unpinned apt, gh, transitive npm and PyPI installs. That is the stale-image risk, and busting those layers would need the same fingerprints anyway.RUNlayers byte-identical. That is noted on the idea as a follow-up; the common case doesn't need it.Image inputs (requirement 3)
apps/api/scripts/*.mjs;container-artifacts/*(content-keyed reproducible vm-agent binary, version json, checksum-verified codex runtime); entrypointsca-certificates jq wget), gh from cli.github.com@anthropic-ai/claude-code,@openai/codex(--ignore-scripts)codex-acp→@openai/codex ^0.159.1)mistral-vibe(96 floating transitive PyPI deps),acp-ampuv pip compilefingerprintThe deploy also builds only the Linux VM-agent binaries now. Nothing uploads or serves darwin builds (
publish-vm-agent-artifacts.sh), andBuild VM Agentwent from 62 s to 21-25 s. The CLI build stays where it is: moving it off the serial path needs a parallel job, which is not a small change.Validation
pnpm lint(pnpm check:fastEXIT 0 before the main merge; ESLint on all changed files after)pnpm typecheck(tsc -p scripts/deploy/tsconfig.jsonafter the latest main merge, 326372c)pnpm test, relevant suites after the latest main merge:scripts/deploy/container-image-*.test.ts;deploy-reusable-workflow.test.ts.Dockerfile.vm-agent-containeris now downloaded over https-only redirects, checked against its sha256 and then run (nocurl | sh); the sort comparator is an explicit code-unit compare.Staging Verification (REQUIRED for all code changes — merge-blocking)
Staging Verification Evidence
| SandboxDO | built | ... | 145s |and| VmAgentContainer | built | ... | 269s |.EDITtosha256:d50031c6...andsha256:5641a3b1...without building anything itself.| SandboxDO | reused | inputs unchanged | 5s |and| VmAgentContainer | reused | inputs unchanged | 5s |.no changes sam-api-staging-sandboxdo-staging,No changes to be madefor both applications.status=completed version=1939 target=1939on its first poll and returned in 1 s.Dockerfile.sandbox):builtunder new keybe5335006db9203b; VM agentreused.EDITto the sandbox only.progressing13 times, then saw it complete (144 s).01M7GB4YR9CQK4TKQ63EBZ38YMon the reused VM-agent image (sha256:5641a3b1) finished its turn; container node deleted at 19:40:54Z. The reply text was not captured, so the check was repeated on staging2.built(352 s resolve), rollout gate 346 s, deploy job 1088 s;be5335006db9203bwas identical to staging's run 3, so the key reproduces across installations.01M7HBJHTKVSJYAE9R4G7CCQT8heartbeated healthy on agent build7bea824b(built from the linux-only VM agent targets). Workspace and node cleaned up, verified in D1.could not read Username). The same flow 90 s after project creation succeeded, and a VM session on the first project cloned fine. This is a pre-existing race unrelated to the images; filed astasks/backlog/2026-11-16-instant-artifacts-new-project-clone-race.md.End-to-End Verification (Required for multi-component changes)
Data Flow Trace
deploy-reusable.ymlruns "Resolve container images".container-image-reuse.ts:main()reads the top-level containers inapps/api/wrangler.tomland the names fromcontainerApplicationNames().resolveContainerImage()runsanalyzeDockerfile(), thenfingerprintInputs(), thencomposeImageKey(), thenlatestRolloutFailed()(createRolloutApi).RegistryIo.lookup()(docker manifest inspect) orbuildAndPush()(container-image-registry.ts).applyImageOverrides()writes[env.<env>].containers[].image.GITHUB_ENVgetsSAM_CONTAINER_IMAGE_OVERRIDES, whichsync-wrangler-config.ts:generateContainerBindings()reads again on the tail re-sync.wrangler deploy,apply()compares image references: an unchanged reference means no rollout.wait-container-rollout.tsruns the gate.Untested Gaps
container-image-registry.ts) is exercised by the staging runs, not by unit tests. Each of its failure modes falls back to a Wrangler build.name unknown), and any other lookup error falls back to Wrangler; both paths build.Post-Mortem (Required for bug fix PRs)
N/A: not a bug fix (deploy speed).
Specialist Review Evidence (Required for agent-authored PRs)
needs-human-reviewlabel added and merge deferred to human: all completed--no-build --no-config, and resolvers run without the deploy secrets. M3: denylist replaced byALLOWED_COMMANDS,REVIEWED_FETCH_URLSand reviewed npm install scripts. M1: registry tag as trust anchor; lookup is now pull-only and the threat model is documented (registry write access is already deploy access). L4: uv installer checksum on the runner. L6: summary newline collapse, credential lifetime cap (efa4cac).imageContextKey(tasks/backlog/2026-11-15-installer-prebuilt-image-key-floating-inputs.md); sandbox decision test added; measurement recorded above.CodeRabbit Review Evidence (Required for agent-authored PRs)
CodeRabbit Notes
Requested at 22:18Z when the PR opened ready:
coderabbit-reviewlabel added, and the trusted bridge workflow (run 43768548404) posted@coderabbitai review. CodeRabbit replied within seconds with "Review limit reached: You've used all free OSS reviews for now" (comment 6902289643) and "Review rate limited" (comment 6902295917), so the wait ended at once per rule 25. No review arrived; not re-triggered.Exceptions (If any)
Agent Preflight (Required)
Classification
External References
wrangler-dist/cli.js):pushImageIfChanged,constructBuildCommand,apply,getNormalizedContainerOptions,resolveImageName.wrangler containers registries credentials --help.InReleaseformat, fetched live.npm install --package-lock-onlyanduv pip compilebehaviour, verified locally.RUNkeyed on instruction text): https://docs.docker.com/build/cache/invalidation/InReleaseindex hashes): https://wiki.debian.org/DebianRepository/FormatCodebase Impact Analysis
.github/workflows/deploy-reusable.yml: two new steps; Linux-only VM-agent build.scripts/deploy/container-image-{inputs,fingerprints,reviewed-inputs,registry,reuse}.tsand their tests.scripts/deploy/installer-engine.vitest.config.tsandscripts/quality/deploy-reusable-workflow.test.ts.apps/api/Dockerfile.vm-agent-container(uv pin, comment) andapps/api/Dockerfile.sandbox(comment).sync-wrangler-config.tsoverrides andcontainer-rollout.ts; neither changed.steps.deploy_resources).Documentation & Specs
apps/www/src/content/docs/docs/guides/self-hosting.mdx, new "Container image reuse" section: behaviour, threat model,CONTAINER_IMAGE_REUSE_ENABLED,CONTAINER_IMAGE_FINGERPRINT_TIMEOUT_MS,CONTAINER_REGISTRY_CREDENTIAL_MINUTES.Constitution & Risk Check
DEFAULT_*constants with GitHub Environment overrides. The registry host and build flags mirror Wrangler.CONTAINER_IMAGE_REUSE_ENABLED=false.🤖 Generated with Claude Code