Plan and ship
Two commands. plan says what would happen, and changes nothing:
$ pnpm infra plan example/guestbook/app.tsguestbook (production)+ d1 book: guestbook-book~ the D1 database guestbook-book: the next ship applies migration 1: migration-pending+ Worker guestbook-guestbook: new, live at once~ rollout: 100%ship makes it so:
$ pnpm infra ship example/guestbook/app.ts 1.28s shipping guestbook-guestbook 1.29s ✓ 739.1 KB of modules 2.01s ✓ created D1 database guestbook-book 2.47s ✓ applied migration 1 to D1 database guestbook-book 3.68s ✓ created Worker guestbook-guestbook, live 8.16s ✓ smoke test passed: 3 × GET /, answered by the new Worker 8.51s ✓ shipped guestbook-guestbook: https://guestbook-guestbook.<you>.workers.devIf you followed Build your first app, you’ve seen both. This page is what’s going on underneath, and the knobs.
Both need a Cloudflare API token in CLOUDFLARE_API_TOKEN, and
CLOUDFLARE_ACCOUNT_ID if the token reaches more than one account.
Reading a plan
Section titled “Reading a plan”A plan reads your account and Effective Cloud’s state, and says, a line each:
| Means | |
|---|---|
+ |
made by this ship |
= |
already there, the app’s, left as it is |
~ |
changed: a new version, a migration, a rollout, an orphan |
! |
a problem a ship stops on, such as a name that isn’t yours |
? |
a contract change the check can’t judge: look yourself |
→ / ← |
what this app uses of other apps, and who uses this one |
The second time round, with a change to the code, the plan for the guestbook reads:
guestbook (production)= d1 book: guestbook-book~ Worker guestbook-guestbook: a new version (code); now 100% on 3bd046c7~ rollout: 100%The database is already the app’s. The Worker gets a new version, which
takes all the traffic once its smoke test passes on the version itself,
before any of that traffic reaches it. The plan says
what the version changes: its code, its assets, its config (the
compatibility date and flags, where it runs, its exports), its
containers, its bindings, each named:
~ Worker guestbook-guestbook: a new version (bindings); now 100% on 3bd046c7~ binding GREETING+ binding LIMITSWith nothing changed, there’s no new version: the plan says
= Worker guestbook-guestbook: unchanged and = rollout: none, and the
ship sets only what’s the Worker’s own (its settings, crons and routes),
in seconds. --force ships a new version anyway. Each version ship
uploads records what it’s made of, in its __SHIP_MANAGED binding, which
is how the next plan knows; a version deployed by another tool, or by
ship before it recorded this, is said as one it can’t compare.
A plan runs infra check’s offline checks first,
and prints what they find above it.
What a ship does
Section titled “What a ship does”In order:
- Checks your code. The same offline checks. An error stops the ship
before it reads your account (
--no-checkskips them, if you must). - Takes the lock for the app and environment, so a second ship of the same thing waits its turn.
- Checks the account, before it makes anything: a resource name
that isn’t the app’s (
name-taken), a Secrets Store secret with no value, a contract change that breaks callers, a route in no zone or serving another Worker. Any of these stop it, with nothing changed. - Ships each Worker, each after the Workers it calls:
- makes the resources it doesn’t have yet,
- applies the databases’ new migrations,
- uploads its files, only those Cloudflare lacks,
- uploads the new version with no traffic, and smoke-tests it,
- moves the traffic to it, and smoke-tests it again (all at once, or
a step at a time with
--steps), - attaches its routes and custom domains, once it’s live.
- Records what it did in the state: what it made, the versions now running, the contracts deployed. Then it detaches the routes and domains you stopped declaring.
A Worker’s first ship goes live at once, as there’s no earlier version to keep the traffic on. If it fails, it’s deleted.
How each Worker rolls out
Section titled “How each Worker rolls out”Each Worker’s rollout is ship’s, the same as for a Worker shipped on its own, so it has a page of its own, How a rollout stays safe:
- smoke tests that check who answered, and behind Cloudflare Access, with a service token;
- all at once, or in steps
(
--steps), and canaries judged on real traffic (--canary); - the undo, on failure or Ctrl-C;
--atomic, for a version that can’t share traffic.
Who may reach it
Section titled “Who may reach it”A Worker says who may reach its workers.dev URL and custom domains, and each ship keeps the Access application that does it:
// Anyone: Access bypassed. Its previews stay private.Worker.make('docs', { domains: ['example.com'], access: Access.public }).bind(Site);// Only those your account's reusable Access policies of these names allow.Worker.make('admin', { fetch, access: Access.only('team (one-time PIN)') });Take access out, and the next ship removes the application: your
account’s own Access decides again. Behind Access, the code can ask who’s
asking, a person or a service token, from the token Access signed:
class Team extends Access.Team<Team>()('myteam.cloudflareaccess.com') {}const who = yield* Access.identity(Team); // { _tag: 'User', email, ... } or { _tag: 'ServiceToken', clientId }Worker.make('admin', { fetch, access: Access.only('team (one-time PIN)') }).bind(Team);A policy name your account doesn’t have, or a hostname another Access application already covers, stops the
ship before anything is made, and infra check --account says so first.
Saved plans: ship what was reviewed
Section titled “Saved plans: ship what was reviewed”In a team, or a pipeline, you may want a plan reviewed and then exactly that plan shipped, not whatever’s true a few minutes later. Save it:
pnpm infra plan app.ts --out plan.json# … someone reads it, approves …pnpm infra ship app.ts --plan plan.jsonThe saved plan holds what the plan read: each Worker’s code and settings
as it would deploy (hashed), the Workers’ current deployments, the
resources as they resolved, and the contracts the state records. The ship
checks all of it again, under the lock. If anything changed (a commit, a
deploy from elsewhere, a resource deleted), it ships nothing and says
what changed, as plan-stale.
A saved plan ships with the options it was made with, so --steps,
--canary, --atomic and --no-smoke go on the plan, not the
ship. It’s for one environment, too: the one it was planned for.
Checked live: a saved plan shipped, and the same plan, tried again, was refused.
Builds: made once, shipped anywhere
Section titled “Builds: made once, shipped anywhere”A pipeline usually builds once and deploys what it built, to staging and
then to production, rather than building again for each. infra build
does that:
pnpm infra build app.ts --env staging --env production --out build/# … later, elsewhere: no source needed …pnpm infra ship --build build/ --env stagingpnpm infra ship --build build/ --env productionThe build is a directory: each environment’s release (the app’s
declarations for it, and each Worker’s code and files named by their
hashes), each file stored once, and build.json, which names each
environment’s release by its id. The build’s own id is the hash of
build.json, so the same build is the same id wherever it goes.
- The code is the same in every environment, so production runs the
code staging ran. What differs by environment, such as a queue’s name
in the account, reaches the Worker as a binding when it ships, not
built into its code.
infra buildstops if a Worker’s code would differ between two of the environments. - Container images are built and pushed once, and copied, by their digests, into each environment’s own repository as it ships. Production runs the very image staging ran, and tearing staging down deletes staging’s copies alone.
- Shipping a build checks it as it reads it: each release against its id, each file against its hash.
A build can live in an R2 bucket of the account instead of a directory.
--out r2://<bucket> writes it there and prints its reference, which
--build takes like a directory:
pnpm infra build app.ts --env staging --env production --out r2://shop-builds# built shop for staging, production: the build 2be70ff3…, at r2://shop-builds/2be70ff3…pnpm infra ship --build r2://shop-builds/2be70ff3… --env stagingBuilds in one bucket share their files, each stored once. Read back, a
build is checked against the id it’s named by. Through a deployer
(--via), the deployer reads the build from the bucket itself, so
nothing but the reference leaves the machine that ships it.
Roll back
Section titled “Roll back”pnpm infra rollback --app shop --env production# rolling shop (production) back to the build 2be70ff3a1c4, which it ran from 2026-10-23T18:02:11Z; it runs 9d41c0e7b2f5 nowThe state keeps the last 5 builds each environment ran, newest first,
and where each is. rollback ships the newest one the environment
doesn’t run now, as ship --build would; give a build’s id (or the
start of it) to go to another: infra rollback 2be70ff3 --app shop --env production. It takes ship’s flags, and --via rolls back through
a deployer. A build is found again when it was shipped from a bucket
(r2://…); one shipped from a directory isn’t, and rollback says so.
A teardown forgets what the environment ran. Checked live: two builds
shipped in turn, then rolled back, the Worker answering as the first
build did again.
Old builds, swept
Section titled “Old builds, swept”Builds aren’t kept for ever. infra build prune sweeps a bucket of
them:
pnpm infra build prune r2://shop-builds --dry-run# would delete 41 objects (5120.3 KB) from r2://shop-builds: 6 builds' indexes, …It keeps every build an environment runs (as the state records, so a
build that’s run in production for a year stays), the last 5 each ran
(what rollback goes back to), and every build made in the last 30
days (--keep-days).
The others’ indexes go, then the releases and files no build kept
needs. Builds share their files, so a file goes only when no kept build
uses it. Nothing less than a day old is ever deleted, and a build being
written puts again any file it relies on that’s over half a day old, so
a sweep can’t take a file from under it. A deployer
sweeps the buckets it’s given daily.
Checked live on a throwaway bucket: what an environment ran was kept
with --keep-days 0, and a build no environment ran, made minutes
before, was left for its day’s grace.
infra plan --build build/ --env production plans it the same way, and
--via sends it to a deployer. A resource the app
declares as provided at deploy
(Files.provided('filesBucket')) isn’t in the build: --provide or
--provided gives its name when it ships.
Promote: what ran in staging, to production
Section titled “Promote: what ran in staging, to production”pnpm infra promote --build build/ --from staging --to productionEach ship from a build records which release it shipped, and from which
build. promote ships production’s release of the build only if staging
was last shipped the build’s release for staging, so what reaches
production is what ran in staging. If staging was shipped from its
module since, or from another build, it ships nothing and says so. It
takes the same flags as ship.
A build in a bucket promotes through a deployer too, with no token where it runs:
pnpm infra promote --build r2://shop-builds/2be70ff3… --from staging --to production --via https://ship-deployer.<your-subdomain>.workers.devThe deployer reads the build, and holds the promotion to what staging runs as its state records it, when it plans and again just before it ships, so a staging that changed in between stops it. Checked live: a promotion refused until staging ran the build, then shipped to production from a shell with no token.
Checked live: an app built for staging and production, its source moved away, shipped to both from the build, then planned again from it, unchanged; and promoted from staging to production, refused until staging ran the build. A ship through a deployer from a build in a bucket records the build too, so it can be promoted from the same way.
Through a deployer: no token here
Section titled “Through a deployer: no token here”A laptop or a CI job needn’t hold a Cloudflare token at all. --via
ships, or plans, through a deployer instead, with only
an Access service token it lets in:
CF_ACCESS_CLIENT_ID=... CF_ACCESS_CLIENT_SECRET=... pnpm infra ship app.ts --via https://ship-deployer.<your-subdomain>.workers.devThe deployer says how an app gets there,
and that a ship through it takes what one here does, --force,
--canary and saved plans included. infra destroy app.ts --via <url>
tears an environment down through it the same way.
The flags
Section titled “The flags”infra ship |
|
|---|---|
--env <name> |
another environment; production by default |
--steps 10,50,100 |
the rollout’s percentages; 100, all at once after the smoke test, by default |
--canary 10,50 |
steps judged on Workers Analytics’ error rates, rolled back if worse |
--bake 60s |
how long each canary step serves before it’s judged |
--canary-strict |
a canary step too quiet to judge fails |
--no-smoke |
no smoke tests |
--atomic |
live before its smoke test, for a version that changes Durable Object classes |
--allow-breaking |
ship a contract change that breaks deployed callers (Workers calling Workers) |
--take-routes |
take routes and domains that serve other Workers (Websites) |
--force |
a new version of each Worker, even when the deployed one is the same |
--no-check |
skip the offline checks |
--plan <file> |
ship a saved plan |
--build <dir> |
ship a build (a directory, or r2://<bucket>/<build id>), in place of app.ts |
--via <url> |
ship through the deployer at url, with an Access service token it lets in (or its key, in SHIP_DEPLOY_KEY) and no token here |
infra plan takes --env, --steps, --canary, --atomic and
--no-smoke (as the plan’s options), --json for a
report, --out <file> to save it, --build <dir>
to plan a build, and --via <url> to plan through a deployer.
Good to know
Section titled “Good to know”- A ship takes seconds per step: about eight seconds for the guestbook’s first, with its smoke test, by ship’s clock, after the checks before it (ten to twenty seconds more). A smoke test can wait longer while a brand new workers.dev URL warms up; ship’s own first live test waited out a minute of it.
- An undo that fails even after retries is logged with
!before the ship ends, so you know what to look at. - infra ships with ship, which you can also use alone, for a Worker that isn’t declared in Effect.
- A Worker a Vite project builds (
Worker.vite, see Local development) is built byvite buildin each plan and ship, and shipped with the bindingsapp.tsdeclares; its compatibility date and flags are its build’s unless it declares them.