Skip to content

feat(deploy): the deploy pipeline, with its own rollback, manual gate and controls - #165

Merged
aRustyDev merged 1 commit into
mainfrom
feat/deploy-workflow
Nov 14, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
feat/deploy-workflow

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

The third of four staged PRs for the deploy pipeline (#49, ADR-0110 round 29). #153 (version header, smoke) and #154 (migrate over verified TLS, the Access-tunnel script) are merged. This adds deploy.yml and everything it runs. The last PR (hashed assets, docs and the ADR note) finishes the work; #49 stays open until then.

Nothing deploys when this merges. Automatic deploys wait for the repository variable THRUST_DEPLOY_ENABLED=true, and a manual run needs an environment that has its variables. Until then a merge to main plans, sees the switch off, and stops.

How a run goes

Job Holds Does
plan no secret Which event, which commit. A push to main deploys staging after ci passed; a manual run names staging or production and a commit of main, and must itself run from main; a pull request is a dry run. The commit's own gate must have passed, asked for by name on that commit, and the environments that gate the deploy must have required reviewers (GitHub creates an unprotected one if a name is mistyped, which would silently open the manual gate)
build no secret The Worker and the migrate binary into one bundle, attested (SLSA provenance)
deploy (env <env>) the environment's secrets Verify the attestation; render the configuration from the environment's variables; read what is live; classify the change; run the expand migration only if migration files changed; wrangler deploy --tag <sha> at 100 %; the smoke; the smoke's control (it must refuse a version nobody deployed). A failing smoke ends in wrangler rollback to the previous version and a probe showing it answer. The run stays red
deploy-do (env <env>-do-lifecycle, reviewers) the same secrets What deploy deferred: the first deploy to an environment, any change to [[migrations]], a live state that cannot be read. deploy finds that out first and deploys nothing; this job deploys after approval, with no automatic rollback (Cloudflare refuses a rollback across a Durable Object lifecycle change)
dry-run none A pull request that touches the deploy files: build the bundle and let wrangler deploy --dry-run check the rendered configuration. It is what shows, before the merge, that this workflow starts

Each secret reaches only the process that needs it: wrangler gets the Cloudflare token and nothing of the database, the tunnel or the smoke account; the expand step gets the database's and the tunnel's but not the Cloudflare token; the smoke gets only its own account. A test has each fake report what it could see.

Operating it (the owner's side)

  1. Environments staging, staging-do-lifecycle, production, production-do-lifecycle exist. Required reviewers on staging-do-lifecycle, production and production-do-lifecycle: plan refuses to start a deploy if they are missing. Deployment branches restricted to main is worth setting too.
  2. Each environment holds the same set (so staging and staging-do-lifecycle are copies of each other): variables CLOUDFLARE_ACCOUNT_ID THRUST_WORKER_NAME THRUST_BASE_URL THRUST_HYPERDRIVE_ID THRUST_R2_BUCKET THRUST_QUEUE THRUST_QUEUE_DLQ THRUST_RL_CREATE_ID THRUST_RL_SIGNIN_ID THRUST_RL_V1_ID THRUST_CSRF_ENFORCE DB_ACCESS_HOSTNAME SMOKE_EMAIL SMOKE_WORKSPACE (and SMOKE_PROJECT, default smoke); secrets CLOUDFLARE_API_TOKEN TUNNEL_SERVICE_TOKEN_ID TUNNEL_SERVICE_TOKEN_SECRET DATABASE_URL SMOKE_PASSWORD. A missing variable is named in the run's error and nothing is deployed. THRUST_CSRF_ENFORCE has no default on purpose: turning it on for production should be a decision.
  3. The first staging deploy: dispatch staging with first_deploy_skip_smoke (the hostname does not exist yet). deploy defers, you approve deploy-do, the schema is made and the Worker is created. Then infra attaches the Custom Domain (ApiraTech/infrastructure #1017), you run scripts/smoke-bootstrap.sh once, and a normal dispatch of the same commit runs the smoke for real.
  4. The rollback drill (issue chore(cd): deploy pipeline per ADR-0110 round 29 (expand, deploy 100 %, smoke, auto-rollback) #49 acceptance): dispatch staging with inject_smoke_failure after any normal deploy. Expect a red run, a wrangler rollback, and the previous version answering. Refused for production.
  5. Flip THRUST_DEPLOY_ENABLED=true when you want pushes to deploy.

Decisions to look at

  • The switch (THRUST_DEPLOY_ENABLED): without it every merge would start a deploy to an environment that does not exist.
  • first_deploy_skip_smoke exists because a Custom Domain needs the Worker to exist first. scripts/deploy-worker.sh refuses it for any environment that already has a live version, and before a reviewer is asked to approve anything.
  • The attestation is not bound to the commit by --source-digest. On a workflow_run the workflow's own commit is the tip of main, not the commit ci ran on. The bundle names the commit it was built from inside the attested file, and the deploy compares that with its own.
  • cloudflared is a pinned release binary (2026.10.7, SHA-256 checked, and checked again by me against a download on 2026-11-14).
  • The pull-request dry run builds the Worker (a cold-cache release build) but only for pull requests that touch the deploy files.
  • ADR-0101/0110 deviation, as you decided: a scoped Cloudflare API token in each environment's secrets, because Cloudflare documents no OIDC federation for wrangler. The ADR note comes in the last PR.

Tests and controls

Everything below runs in ci-scripts (under dash) or deps.

  • scripts/deploy-worker.sh against a fake Cloudflare that keeps state (what the edge serves). The smoke is truthful about it, so a rollback verifies only if it really made the previous version answer. Cases: an ordinary deploy; migrations before the deploy; a failing expand step; a stale edge; a broken app; an injected failure; a smoke that accepts any version (caught by the control, rolled back); a failed and an unverified rollback; the first deploy and a lifecycle change at the manual gate (deferred, nothing deployed, no automatic rollback even when the smoke fails); an unreadable live state; refusals before anything is touched; the secrets each process sees.
  • plan-deploy.sh over every combination of its finite inputs (2,640), classify-deploy.sh over every pair of commits of a real history against a state-based oracle, assert-sha-checks.sh and assert-gated-environments.sh against a fake gh, render-wrangler.sh --self-test, a parity test of wrangler.deploy.toml against wrangler.toml, a pin of the CA root's fingerprint, and lint-workflow.sh with a broken copy for each of its seven rules.
  • Mutation: each script was broken by hand, one way at a time, 69 ways, and its own test caught 68. The one it did not is a redundant guard that cannot be reached. Three first survived and showed gaps, now covered (one pair of equal rate-limit ids tested; no stale file to show a refused render removes it; nothing pinning that only a required_reviewers rule counts).
  • Real tool checks: I built the Worker with worker-build and ran wrangler deploy --dry-run on the rendered template (wrangler 4.123.0 locally; CI uses the pinned 4.151.2): the bindings are exactly the intended ones, with no credentials. The CI dry-run job repeats it on this PR.
  • crates/thrust-adapters-postgres/tests/tls.rs reads the real Cloudflare Origin CA root the deploy trusts (byte for byte the file Cloudflare publishes) and shows rustls accepts it as a verify-ca root, with a control.

Faults the tests and the real build found, corrected here: the renderer accepted a name with a capital letter in a UTF-8 locale on macOS ([a-z] matched it); jq | sort || fail tested sort's status and read a jq failure as "nothing reported"; the first bundle copied build/worker/ only, when worker-build also writes build/index.js and build/index_bg.wasm, which the shim imports, so the deployed Worker would not have started.

Not verified

None of this has run against Cloudflare or GitHub's environments, and this PR's own CI run is the first time deploy.yml starts.

  • The shape of wrangler deployments list --json and versions list --json. The parser accepts the documented one and treats every other as "cannot tell", which sends the deploy to the manual gate and never to an automatic rollback. The first staging deploy settles it.
  • That wrangler deploy attaches the queue consumer with a dead-letter queue, and the token scopes it needs (likely Queues > Edit as well as Workers Scripts > Edit).
  • The attestation flow end to end (gh attestation verify with these flags on a real attestation).
  • That the workflow's GITHUB_TOKEN can read an environment's protection rules. If it cannot, plan fails closed with a message that says so, and the remedy is a permission, not a weaker check.
  • The route to the database (infrastructure #1015, #1016, #1017: work has started) and Access accepting the service token.

Checks run locally

cargo fmt --all --check, clippy on every target and for the wasm Worker, cargo nextest run --profile ci --workspace (3,868 passed), the doctests, check-deps, check-topology (with its self-test), check-placement, render-wrangler.sh --self-test, lint-workflow.sh, and all the script tests under dash.

Refs: #49

🤖 Generated with Claude Code

… and controls

The third of four staged PRs for the deploy pipeline (ADR-0110 round 29). It adds `deploy.yml` and everything it runs: build a bundle of
the commit with no secret in the job, attest it, deploy it to an environment, prove it with the smoke, and roll back by itself when the
proof fails. Nothing deploys until the repository variable THRUST_DEPLOY_ENABLED is `true` and the environments have their variables.

How a run goes (.github/workflows/deploy.yml, scripts/deploy-worker.sh):
- plan: what the event is and which commit. A push to main deploys staging after `ci` passed; a manual run names an environment and a
  commit of main, from main; a pull request is a dry run. The commit's own `gate` must have passed, asked for by name on that commit,
  and the environments that gate the deploy must have required reviewers (GitHub creates an unprotected one if a name is mistyped).
- build: the Worker and the `migrate` binary, in a job with no secret, into one bundle, attested (SLSA provenance).
- deploy (environment `<env>`): verify the attestation, render the configuration from the environment's variables, read what is live,
  classify the change against it, run the expand migration only when migration files changed, `wrangler deploy --tag <sha>` at 100 %,
  the smoke, and the smoke's control (it must refuse a version nobody deployed). A failing smoke ends in `wrangler rollback` to the
  previous version and a probe that shows it answering; the run stays red.
- deploy-do (environment `<env>-do-lifecycle`, with reviewers): the first deploy to an environment, any change to `[[migrations]]`, and
  a live state that cannot be read are not made by `deploy`: it finds that out first, deploys nothing, and this job deploys them after
  approval, without an automatic rollback (a rollback is refused across a Durable Object lifecycle change).
- dry-run (a pull request that touches the deploy files): the bundle is built and wrangler checks the rendered configuration with
  --dry-run. No environment, no secret. It is what shows, before the merge, that the workflow starts.

The pieces, each a script with a test (all run in `ci-scripts`, under dash): scripts/render-wrangler.sh with crates/thrust-worker/wrangler.deploy.toml
(the template; the renderer refuses an unset variable, an all-zero id, a thrust-spike name, an unknown marker); .github/scripts/
classify-deploy.sh (does the expand migration run, is it a lifecycle change); active-version.py (which version is live and its tag);
plan-deploy.sh; assert-sha-checks.sh; assert-gated-environments.sh; lint-workflow.sh (pinned actions, explicit permissions, no expression
in a `run:`, secrets only in the two gated jobs); scripts/deploy-worker.sh and its test, which runs the whole flow against a fake
Cloudflare that keeps state (what the edge serves), so the rollback, the control and the manual gate are shown before staging exists.

The tests found real faults, fixed here: the renderer accepted a name with a capital letter in a UTF-8 locale on macOS (`[a-z]` matched
it); `jq | sort || fail` tested sort's status and read a jq failure as "nothing reported"; and the first bundle copied `build/worker/`
only, when worker-build also writes `build/index.js` and `build/index_bg.wasm`, which the shim imports (found by building the Worker
and running wrangler on it). Each script was also broken by hand, one way at a time, 69 ways in all, and its own test caught 68 of them;
the one it did not is a redundant guard (a leftover-marker check that cannot be reached once the earlier checks pass). Three first
survived and showed gaps, now closed: only one pair of equal rate-limit ids was tested, no stale rendered file existed to prove a refused
render removes it, and no case pinned that only a `required_reviewers` rule counts as a gate.

crates/thrust-adapters-postgres/tests/tls.rs now reads the Cloudflare Origin CA root the deploy trusts (.github/deploy/, byte for byte
the file Cloudflare publishes, its fingerprint pinned by a test) and shows rustls accepts it as a `verify-ca` root, with a control.

Deviates from ADR-0101 and ADR-0110 on one point, on the owner's decision: the Cloudflare credential is a scoped API token in the
environment's secrets, because Cloudflare documents no OIDC federation for wrangler. The deviation goes into the ADR in the last PR.

Not verified: any of it against Cloudflare. The shape of `wrangler deployments list --json` and `versions list --json` is the documented
one (the parser treats every other shape as "cannot tell", which sends the deploy to the manual gate); the attestation flow, the token's
scopes, and `wrangler deploy` attaching the queue consumer with a dead-letter queue have not run. The first staging deploy is the check.

Refs: #49
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit 67e3a6f into main Nov 14, 2026
40 checks passed
@aRustyDev
aRustyDev deleted the feat/deploy-workflow branch November 14, 2026 18:15
aRustyDev added a commit that referenced this pull request Nov 14, 2026
…r deletion

Main gained #165, the deploy pipeline, while this branch's PR was open. The merge is clean as text, with no conflicts, and it adds no contract test (EXPECT_MAIN stays 73). It is not clean in meaning: the pipeline's template, renderer, workflow and action declare the `RL_CREATE` binding this branch deletes, and `test-deploy-template.sh` holds the template to the same bindings as wrangler.toml, so the template has to follow. That is the next commit.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev added a commit that referenced this pull request Nov 14, 2026
…ation

The deploy pipeline (#165) declared the binding that this PR's earlier commit deletes from the Worker and the other configs: the template crates/thrust-worker/wrangler.deploy.toml had an `RL_CREATE` block with a `__RL_CREATE_ID__` marker, scripts/render-wrangler.sh filled it from `THRUST_RL_CREATE_ID`, and deploy.yml and the deploy-worker action passed that variable through. Left alone it fails CI: `test-deploy-template.sh` requires the template and wrangler.toml to bind the same things (`deploy_parity.py`), and the template would still have a binding wrangler.toml no longer has. My first push did not have #165 in it; the failure was found when main moved, by searching its tree for the names this PR deletes.

Changed:
- wrangler.deploy.toml: the `RL_CREATE` block and its marker go; the comment says the environment has two namespace ids, not three, and that there was a third.
- render-wrangler.sh: the marker, the variable, the id list in the header and the self-test fixtures go, and the rule that the ids differ is about two ids now (its message says "the two"; the self-test's fragment "must differ from one another" still matches). The cases for `THRUST_RL_CREATE_ID` unset and empty and for the two equalities that involved it go with it (four cases). Two cases are added, as the control for the removal: a template that still has the retired `__RL_CREATE_ID__` marker is refused ("which this script does not know"), with or without `THRUST_RL_CREATE_ID` still in the environment, so a stale template cannot be rendered into a config that declares a binding the Worker does not use.
- The deploy-worker action loses its `rl-create-id` input and its `THRUST_RL_CREATE_ID` env; deploy.yml loses the variable from its list of an environment's variables, from the dry run's environment and from both `rl-create-id:` inputs; test-deploy-worker.sh drops it from its good environment.
- G-26 records this.

Checked, under dash in an Ubuntu 24.04 container (CI's shell) on this tree and, as a baseline, on origin/main, with python3, jq and nc installed: every test of the `ci-scripts` job and both deploy guards (the renderer's `--self-test` and the workflow lint of deploy.yml and the action) pass on both. The renderer's self-test is 43 ok on this tree and 45 on main: four cases removed, two added. `scripts/check-placement.sh` passes. clippy and rustfmt are clean on the merged tree.

Control: main's template against this wrangler.toml fails the parity check (exit 1: the template has `RL_CREATE`, wrangler.toml does not); the fixed template agrees.

The `THRUST_RL_CREATE_ID` variable of the GitHub environments is unused now. It is harmless and deleting it is the owner's. A deploy of this commit renders a config with two rate-limit bindings and a Worker that asks for those two.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev added a commit that referenced this pull request Nov 14, 2026
…nd its settings (#166)

* refactor(rate-limits): delete the slice's create limit, its binding and its settings

Step 5c-3c of moving off /api/_slice, the last piece of step 5c-3 (the owner's order was the core, then the adapters, then this, one PR each). The per-user create limit was applied by the slice's `create_work_item`, which #161 deleted. Nothing reads it now, and /api/v1 has its own per-key allowance.

Deleted:
- `CoreConfig.create_rate_limit` and `THRUST_CREATE_RATE_LIMIT`, in the native server and the Worker.
- `CoreConfig.rate_window_secs` and `THRUST_RATE_WINDOW_SECS`, and the Worker's startup check of that window. Only the create limit's use-case read them (checked: no other reader in the workspace); /api/v1's window is the period in `THRUST_V1_RATE_LIMIT` and sign-in's is a constant of the core's config.
- The `RL_CREATE` binding and its `[[ratelimits]]` block in wrangler.toml, wrangler.stage2.toml and wrangler.pg.stage.toml, and the Worker's `env.rate_limiter("RL_CREATE")`.
- In thrust-adapters-cloudflare, `KeyClass::Create` and `CfRateLimiter.create`. A key that starts with `create:` is a key of no class now: an error, never a free pass. The tests list it, as three refused keys.
- `Target::create_limit` (no caller) and `THRUST_EXPECT_CREATE_LIMIT`; `THRUST_WORKER_CREATE_LIMIT` and the create handling in scripts/worker-dev.sh; `RATE_LIMIT` in scripts/contract.sh; the create refusal in scripts/stage2-contract.sh.

One option is retargeted, not deleted: `scripts/spike-0002-pg.sh deploy --create-limit N` is `--v1-limit N` and rewrites the `RL_V1` limit (marker `__V1_LIMIT__` on that line, default 60). The engine pass goes through /api/v1, so RL_V1 is the binding it needs raised on a deployed Worker; `--create-limit` raised one that the pass no longer touched. The infra, contract-suite and defect-matrix pages and G-26 say so.

Operations: the Worker built from this commit and this commit's config are a pair. The code no longer asks for `RL_CREATE` and the config no longer declares it, so the previous Worker with this config would fail to start (it asks for a binding that is not there). Deploy them together.

The two assertions that changed in thrust-adapters-cloudflare/tests/rate_limiter.rs are the class list (two classes, not three) and the setting name the period tests pass to `check_binding_period`, which was `THRUST_RATE_WINDOW_SECS` and is the name the Worker still passes (`the period of THRUST_V1_RATE_LIMIT`).

Checked: native-memory main 70 of 70, sweeper 3 of 3, csrfoff 6 of 6, engine 4 of 4; worker-memory main 70 of 70; worker-cf main 70 of 70 and bindings 5 of 5, from a config with RL_SIGNIN and RL_V1 only; `cargo nextest run` 3860 of 3860 (6 fewer than before: the class tests have 2 classes where they had 3, and the 3 refused keys are added); doctests; clippy and rustfmt; `sh -n` of the four changed scripts under dash (an Ubuntu container). One test, thrust-api-v1's `parity_slugify_of_drawn_names_is_the_pins`, was reported "leaky" once in the full parallel run and passed clean in three solo runs; it is in a crate this change does not touch.

Controls, temporary and reverted:
- `create` mapped to a class again in `KeyClass::of`: the 3 refused-key cases fail, 127 others pass.
- a Worker that asks for a binding its config lacks never comes up (wrangler: "Binding ... is undefined", exit 4), so the worker-cf cell catches a binding mismatch and its pass without RL_CREATE is evidence.
- stage2-contract.sh refuses `THRUST_EXPECT_V1_LIMIT=1000000` (exit 2) and passes the guard at the default.
- the spike script's `sed` on the staging template changes only the RL_V1 line (a dry run; nothing is deployed from here).
- the dash check of the scripts fails a deliberately broken script.

Not run: native-pg (CI runs it) and any deploy.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* refactor(deploy): drop the RL_CREATE binding from the deploy configuration

The deploy pipeline (#165) declared the binding that this PR's earlier commit deletes from the Worker and the other configs: the template crates/thrust-worker/wrangler.deploy.toml had an `RL_CREATE` block with a `__RL_CREATE_ID__` marker, scripts/render-wrangler.sh filled it from `THRUST_RL_CREATE_ID`, and deploy.yml and the deploy-worker action passed that variable through. Left alone it fails CI: `test-deploy-template.sh` requires the template and wrangler.toml to bind the same things (`deploy_parity.py`), and the template would still have a binding wrangler.toml no longer has. My first push did not have #165 in it; the failure was found when main moved, by searching its tree for the names this PR deletes.

Changed:
- wrangler.deploy.toml: the `RL_CREATE` block and its marker go; the comment says the environment has two namespace ids, not three, and that there was a third.
- render-wrangler.sh: the marker, the variable, the id list in the header and the self-test fixtures go, and the rule that the ids differ is about two ids now (its message says "the two"; the self-test's fragment "must differ from one another" still matches). The cases for `THRUST_RL_CREATE_ID` unset and empty and for the two equalities that involved it go with it (four cases). Two cases are added, as the control for the removal: a template that still has the retired `__RL_CREATE_ID__` marker is refused ("which this script does not know"), with or without `THRUST_RL_CREATE_ID` still in the environment, so a stale template cannot be rendered into a config that declares a binding the Worker does not use.
- The deploy-worker action loses its `rl-create-id` input and its `THRUST_RL_CREATE_ID` env; deploy.yml loses the variable from its list of an environment's variables, from the dry run's environment and from both `rl-create-id:` inputs; test-deploy-worker.sh drops it from its good environment.
- G-26 records this.

Checked, under dash in an Ubuntu 24.04 container (CI's shell) on this tree and, as a baseline, on origin/main, with python3, jq and nc installed: every test of the `ci-scripts` job and both deploy guards (the renderer's `--self-test` and the workflow lint of deploy.yml and the action) pass on both. The renderer's self-test is 43 ok on this tree and 45 on main: four cases removed, two added. `scripts/check-placement.sh` passes. clippy and rustfmt are clean on the merged tree.

Control: main's template against this wrangler.toml fails the parity check (exit 1: the template has `RL_CREATE`, wrangler.toml does not); the fixed template agrees.

The `THRUST_RL_CREATE_ID` variable of the GitHub environments is unused now. It is harmless and deleting it is the owner's. A deploy of this commit renders a config with two rate-limit bindings and a Worker that asks for those two.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant