Skip to content

The deployer

The deployer moves the deploy itself into Cloudflare. The machine that ships sends it what to deploy, and the deployer, holding the token, provisions, uploads, rolls out and smoke-tests, streaming its log back. It ships one Worker, as ship does, or a whole app, as infra ship does. The machine that ships holds no Cloudflare token at all: Cloudflare Access says who may ask the deployer, and the deployer’s own token, made for it alone, stays inside it.

From your machine, with your own credentials (CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID), which never reach the deployer:

Terminal window
pnpm --filter @forge-effect/deployer run setup -- --name ship-deployer path/to/app.ts [more apps…]

(run matters: pnpm setup is pnpm’s own command.) The apps’ paths are from where you run it. It loads them first, and checks it can make the deployer’s token, so a mistake stops it before it makes anything.

Setup makes, or keeps, three things:

  • An Access application of its own, on the deployer’s hostname, letting in whom the account’s Access application over all Workers lets in, in the same order (or the reusable policies you name with --policy).
  • An API token for the deployer, owned by the account rather than by you, no wider than shipping the apps you name needs, and lasting 90 days (--days). One made before for it is deleted. If you may not make account tokens, someone who may makes it, and you pass it with --token-from-env (DEPLOYER_API_TOKEN).
  • The deployer itself, shipped with both: Access’s team and the application’s audience, which it checks every request against, and the token, as its secret.

GET /status says who’s asking and how long the deployer’s token has left, and warns under two weeks. setup --name ship-deployer --rotate rolls the token and sets the new one; the old one stops at once, so rotate between deploys.

setup --name ship-deployer --remove takes it down: the deployer, its bucket of releases (its runs and plans with it), its Access application, and the token setup made. What it shipped stays; tear an app down with infra destroy … --via, below, first.

Every route but /health takes someone Access let in. The token Access puts on the request is checked against the team’s keys, for the audience of the deployer’s own application, never on the token’s word. A person is their email; a service token, service-token:<client id>. Each deploy records who asked.

DEPLOYERS (--deployers <json> at setup) narrows that further: who may deploy which apps and environments, with patterns such as shop/pr-*, and a Worker shipped on its own as workers/<name>. Left out, anyone Access lets in may deploy anything.

A pattern written plan:<pattern> lets someone plan an environment but not apply the plan. What they plan waits in the console until someone who may ship that environment applies it. So CI plans production, and a person approves:

{
"service-token:ci.access": ["shop/staging", "plan:shop/production"],
"you@example.com": ["shop/*"]
}

A plain pattern lets someone plan and apply, so leave production out of CI’s. Each run records who planned it beside who applied it.

The deployer’s own page, at /console/ on its hostname, behind its Access application, showing what DEPLOYERS lets you see:

  • Every environment, with the build it runs, how its last deploy went, and whether a run holds it now.
  • One environment: each Worker’s traffic, version by version; the plans waiting, with what each changes, to apply; the last builds it ran, each with a rollback to plan; a promotion of the build it runs to another environment; and its runs, with who planned and who applied each.
  • Errors in the last 15 minutes, each Worker’s requests and errors by version, as Workers Analytics counts them and a canary judges them.
  • A run, its log as it’s written, whoever started it, and while it goes, a button to cancel it: the run stops and undoes what it did, as a failed ship does, and is recorded as cancelled, by whom.

A rollback or a promotion from the console is a plan like any other: made by the deployer, shown to you, and applied only as it was planned, or not at all if what it read has changed since. The console takes no secrets, so a plan that sets them is applied from the CLI or Pulumi.

Changes the deployer takes from a browser must come from its own pages: Access’s login is a cookie a browser would send from any site.

Ship a Worker through it with an Access service token it lets in:

Terminal window
CF_ACCESS_CLIENT_ID=... CF_ACCESS_CLIENT_SECRET=... \
pnpm --filter @forge-effect/ship ship path/to/project --prebuilt --via https://ship-deployer.<your-subdomain>.workers.dev
  • A Durable Object per Worker runs one ship at a time, so two deploys of a Worker never race.
  • A ship it started finishes, or is undone, even if the client goes away.
  • It keeps each Worker’s last 20 deploys (GET /deploys/<name>).
  • A Worker shipped on its own takes no --canary or --secret through it yet, and is refused either; an app’s ship takes both, below.

Checked live: a first ship through it, provisioned and smoke-tested from inside the deployer, and a stepped rollout, each step answered by the new version, with its log streamed back.

infra’s --via ships an app through it the same way:

Terminal window
CF_ACCESS_CLIENT_ID=... CF_ACCESS_CLIENT_SECRET=... pnpm infra ship app.ts --via https://ship-deployer.<your-subdomain>.workers.dev
CF_ACCESS_CLIENT_ID=... CF_ACCESS_CLIENT_SECRET=... pnpm infra plan app.ts --via https://ship-deployer.<your-subdomain>.workers.dev

The app is built on your machine as a release: its declarations as data, and each Worker’s code and files named by their hashes. The deployer is sent the release, then only the files it hasn’t got. It plans the release against the account and the state, as infra plan does, then ships exactly that plan, holding the same lock the CLI takes, so the two never race. Its log streams back as it goes, and it keeps the app’s runs (GET /apps/<app>/<env>/runs), each with who asked.

infra destroy app.ts --via … tears an environment down through it, with no Cloudflare token on your machine either, saying what it deleted (--allow-data-loss for production, as here).

A build goes the same way: infra ship --build <dir> --env production --via … sends the build’s release for that environment, with no source on the machine that sends it.

The deployer runs only its own copy of infra. Nothing of the app’s code runs there but the Workers’, on Cloudflare, so being allowed to deploy an app doesn’t let anyone make the deployer do anything else with its token. Through a deployer, a ship takes what one here does: --force makes a new version of each Worker; --canary bakes and judges each step on Workers Analytics, read with the deployer’s token (setup gives it Account Analytics Read); and a plan saved with infra plan … --via <url> --out plan.json (the deployer keeps the plan; the file names it) ships later with infra ship --plan plan.json --via <url>, or nothing if what it read changed. The deployer keeps plans for a week. Checked live: a plan saved, then shipped from the file by its id; and a forced ship with a canary, its step judged on Workers Analytics as the deployer read it.

Checked live: an app with a KV namespace and a D1 database shipped through a deployer from a shell with no Cloudflare token, its migration applied by the deployer, then planned again, unchanged; and a deployer behind its own Access application, set up as above, shipping with nothing but an Access service token.

If the deployer stops in the middle of a run (it was updated, say), the run’s alarm finds it. Each Worker’s traffic goes back to the version the state recorded before the run, which a run that didn’t finish never replaced, as a ship undoes itself when it fails. A Worker that wasn’t deployed before is left as it is, as is anything the run made. The run is recorded as lost, saying what was put back, and its lock on the state released.

Given a build by its reference (infra ship --build r2://shop-builds/<id> --via …, or a Pulumi App’s build: r2://… with via), the deployer reads the build from the account’s bucket itself (POST /builds): its index says which app it is, for DEPLOYERS; its release for the environment is checked against its id, and its files copied to the deployer’s own bucket. Its token needs R2 for that: set up with --build-bucket <name>, it’s made with Workers R2 Storage Edit, and the deployer is told the bucket.

Checked live: a build written to a throwaway bucket, then shipped through a throwaway deployer by its reference alone, from a shell with no Cloudflare token; the deployer read it from the bucket, shipped it, smoke-tested it, and planned it again as unchanged. Its cron was there (23 4 * * *).

infra rollback --app <name> --env <env> --via … rolls back through it: the deployer says what the environment ran (GET /apps/<app>/<env>/ran), and the build before is shipped by its reference as any is.

infra promote --build r2://… --from staging --to production --via … promotes through it: the plan names the environment promoted from (promoteFrom), and the deployer checks that it runs the build’s release, with the same code, when it plans and again as it applies.

A cron runs the deployer’s sweep each day. In its own bucket, a release or a plan is wanted only from the plan to its apply, so those over a week old go, then the files no release kept needs. The buckets of builds it was set up with (--build-bucket, its BUILD_BUCKETS) are swept as infra build prune sweeps them. Nothing under a day old goes; the Worker’s log says what each sweep deleted.

A Pulumi App given via ships the same way, so the machine running Pulumi holds no Cloudflare token. The deployer plans and ships for the stack (pulumi:<project>/<stack>): an environment the stack owns, or no one does, recorded as the stack’s, as if it had shipped it itself. Who may ship as a stack is DEPLOYERS’s to say, by the stack’s name as a pattern ("pulumi:shop/*"), as for an app. The secrets a plan sets are named in it; their values come only with the apply, and the deployer never keeps them. It also gives an environment’s outputs (GET /apps/<app>/<env>/outputs) and tears one down from its declarations (POST /apps/<app>/<env>/teardown), each as the stack.