Repository navigation
feat(deploy): deploy a target as a Worker Preview and prove it through the edge, removing it again on any failure - #257
Merged
Merged
Conversation
…ck the version and the route The smoke of a Preview target must go through the shared hostname (ADR-0111): the edge sends a request to the target only with a pin cookie, which it sets on /_edge/opt-in/<audience>?target=<name> for a principal Access admitted there. Without the pin the answer is production's. Part of #195 stage E; no deploy runs these yet. - scripts/edge-opt-in.sh <shared-origin> <audience> <target> <cookie-jar>: - asks with the CI opt-in service token (EDGE_CI_CLIENT_ID/_SECRET, in a 0600 header file, never argv), and writes the edge's pin (__Host-thrust_edge) to the jar; - asks again only for the refusals that time cures: the edge's "that target does not exist or is not open to you", given until the target's flag has propagated (up to 30 s), a 503, no answer; - every other answer is final: an empty-bodied Access 403, the edge's "not admitted", any other status, a 303 that sets no pin; - refuses, before asking anything, an origin that is not https, and an audience or target outside the edge's own grammar. - scripts/smoke-deploy.sh: - SMOKE_COOKIE_FILE: the pin goes with every request of both phases. The sign-in's session cookies join it in one jar, so the read reaches the same target. - SMOKE_EXPECT_ROUTE: phase 1 also needs the edge's x-thrust-route to name the target. - Without either, the smoke is unchanged. - The new name check spells its letters out: in a UTF-8 locale `[a-z]` also matches capitals. The test found it. Tests (test-smoke-deploy.sh, under dash: 54 passed, in the C and a UTF-8 locale). smoke_stub.py now also stands for the edge with one target (--pin): only a request with that target's pin reaches it, and any other gets production's version, route and an API that answers 421. Cases: - through the edge, both phases reach the target; - without the pin, production's version fails it; - another route, or no route header, fails it; - the opt-in waits out propagation and a transient 503, and gives up after its attempts; - each final refusal is final, not retried; - every usage error asks nothing; - the secret is in no curl argv and in no output (seen through the existing argv-logging curl wrapper). 11 hand mutants of the two scripts each fail it. The first run had one survivor: retrying every 403 still matched the refusal cases' fragment, so those cases now require the message only an immediate refusal prints. Also: every deps step (14) and every ci-scripts test (29), run separately with sh as dash. plan-ci.py routes edge-opt-in.sh with the other deploy scripts (test_plan_ci.py: 5024). A row in cicd.md. Refs: #195 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h the edge, removing it again on any failure The third piece of deploying release candidates as Worker Previews (#195 stage E, ADR-0111). It joins the two before it: the target's configuration (preview-config.py, #241) and the smoke through the edge (edge-opt-in.sh and the smoke's pin and route). No workflow runs it yet: the switch from staging to targets is held until the cut-over. scripts/deploy-target.sh, everything from the environment like deploy-worker.sh: 1. Every input is checked before anything is asked of Cloudflare (exit 2, nothing called): - the name, in the edge's grammar; its Preview label is the name with `.` as `-`; - the commit, the shared origin, the web files, every variable; - the kind, a target kind of the Flagship policy; - the audience, one the policy lets CI reach that kind through (else the smoke could never opt in); - the expiry. 2. Production's configuration is rendered, and the target's derived from it (shared: production's data and rooms). 3. `wrangler preview --name <label> --json --ignore-base-config --tag <sha>`. 4. scripts/preview-result.py reads the answer. Behind the progress lines, it requires: - the URL the edge accepts, https://<label><suffix>; - a deployment id the edge accepts; - every declared binding, in what Cloudflare applied; - every room on the script_name it was given (production's Worker); - every variable with the text it was given (THRUST_PUBLIC_BASE_URL = the shared origin, Q-0111.2). Other bindings are checked by name only: the spike recorded only the shapes of rooms and variables. 5. `flagship.py put`: {url, deployment, release = the commit, kind, data = shared, expires}, read back. 6. The opt-in and the smoke through the edge, with the pin and the target's route. 7. The smoke's control: a version nobody deployed must fail. A failure from step 3 on deletes the flag first, then the Preview, and a failed deploy over a live target therefore leaves no target. A cleanup that fails says what it left. Each tool sees only its own secret: wrangler the Cloudflare token, flagship.py the Flagship token, the opt-in its service token, the smoke its password; the render and the readers none. Tests: - test-deploy-target.sh, under dash: 121 passed. Fakes: target_fakes.py for wrangler's Previews (applying the previews block in the spike's recorded shape), a truthful opt-in and a truthful smoke, and the real flagship.py against flagship_fake.py. It covers: - every target kind deploying, with its Preview and flag checked against a model; - the steps in order, each with only its own secret; - every failure point leaving nothing (no flag, no Preview), and the step-4 ones stopping before any flag is written; - a flag that does not stick; - a failed cleanup saying what it left; - every usage error calling nothing; - a redeploy replacing the Preview and the flag. - test_preview_result.py: 3957 checks. 300 generated previews blocks with Cloudflare's answers behind 0 to 3 progress lines, then every binding dropped, every room's script_name gone or wrong, every variable's text changed, and the URL and the deployment id broken every way the edge refuses. - 17 hand mutants of the two scripts. The first run had one survivor: the deploy carried on past a Preview that was not the one asked for, until flagship.py refused the empty URL, and the message the case looked for was printed either way. Each step-4 failure now also requires that no flag was ever written, and the rerun killed every mutant. - The test found a real bug, fixed here: the cleanup skipped the flag when `put` had failed its read-back, leaving whatever it had written. Also run: every deps step and every ci-scripts test, each separately with sh as dash. plan-ci.py routes both scripts to ci-scripts. A row in cicd.md. .gitignore keeps the two rendered configurations out. Refs: #195 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # .github/scripts/plan-ci.py # docs/src/architecture/cicd.md
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.
Stacked on #253 (its base). It uses #253's
edge-opt-in.shand the smoke's pin and route.Merge that one first; GitHub then retargets this one to
main.The third piece of deploying release candidates as Worker Previews (#195 stage E, ADR-0111). No workflow runs it yet:
release candidates keep deploying to staging until the cut-over.
What it adds
scripts/deploy-target.sh, which takes everything from the environment, asdeploy-worker.shdoes. In order:Checks every input before anything is asked of Cloudflare. A usage error is exit 2, with nothing called. It checks:
.written as-);Renders production's configuration and derives the target's from it (feat(deploy): derive a shared Preview target's configuration from production's rendered one #241, shared data).
Runs
wrangler preview --name <label> --json --ignore-base-config --tag <sha>.Reads the answer with
scripts/preview-result.py. It requires:THRUST_PUBLIC_BASE_URL= the shared origin, Q-0111.2).Other bindings are checked by name only: the spike recorded only the shapes of rooms and variables.
Writes the target's flag with
flagship.py put, which reads it back.Opts in and runs the smoke through the edge, with the pin and the target's route.
Runs the smoke's control: a version nobody deployed must fail.
On any failure from step 3 on, it deletes the flag first, so the edge stops routing to it, then the Preview. A failed
deploy over a live target therefore leaves no target at all. If the cleanup itself fails, it says exactly what it left.
Each tool sees only its own secret:
flagship.pyTests
test-deploy-target.sh, under dash: 121 checks pass.target_fakes.pystands in for wrangler's Previews. It applies thepreviewsblock in the shape the spike recorded,and can be told to deviate.
flagship.pyruns againstflagship_fake.py.before any flag is written;
test_preview_result.py: 3957 checks. It generates 300previewsblocks with Cloudflare's answers behind 0 to 3progress lines, then drops every binding, removes or changes every room's
script_name, changes every variable's text,and breaks the URL and the deployment id in every way the edge refuses.
Hand mutants: 17 versions of the two scripts with a planted bug; each one fails the tests.
flagship.pyrefused the empty URL, so the expected message appeared anyway. Each of those cases now also requires thatno flag was ever written, and the re-run killed every mutant.
A real bug the tests found, fixed here: the cleanup skipped the flag when
puthad failed its read-back, which leftbehind whatever
puthad partly written.Also passing:
depsstep (14);ci-scriptstest (32), each run on its own withshas dash;test_plan_ci.py(5031).Not verified
A real
wrangler preview. Nothing here runs against Cloudflare. The fakes follow the spike's recorded output.apps) and Q-0111.1.
.deployment.env. That is whythey are checked by name only.
Next
deploy.yml. A release candidate deploys as a target and setsalias-staging, behind a switch that stays off until thecut-over. It includes the migration rule for shared data: the newest shared target migrates, behind a reviewer.
Refs #195
🤖 Generated with Claude Code