How a rollout stays safe
Every Worker deploys through ship, whether you run it on a Worker you
already have, or infra ship runs it for each Worker of an app. So a
rollout works the same either way, with the same flags:
pnpm ship path/to/project --steps 10,50,100 # one Workerpnpm infra ship app.ts --steps 10,50,100 # every Worker of an appFor a Worker that’s already live, a ship goes like this:
- It uploads a new version, with no traffic. The deployed version keeps serving everyone.
- It smoke-tests the new version on its own, before any user reaches it, and checks that the new version is the one that answered.
- It moves the traffic over: all at once, a step at a time, or as a canary judged on real error rates.
- If anything fails, or you press Ctrl-C, it undoes everything, in reverse.
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.
Smoke tests that check who answered
Section titled “Smoke tests that check who answered”After each step, ship calls the Worker (GET /) until three requests in a
row succeed. That alone would prove little: mid-rollout, the old
version could answer, and the test would pass.
So ship puts a tiny module in front of your Worker’s code, which answers one unguessable path with the version that’s running. Each step’s test pins its requests to the new version, and passes only if the new version is the one that answered. That’s the “answered by the new Worker” in the log.
- In its first seconds, a new URL can answer with Cloudflare’s own 404 or error page. Those are waited out. A server error (5xx) from your code is asked again for up to a minute, as a new Worker’s dependencies can still be warming up; any other failure from your code fails the test at once. So a version that answers 500 fails after about a minute, not at once.
- A Worker with no
fetchgets one, for the probe alone, and its tests count no requests. - A Worker that hosts Durable Objects has no preview URLs, so its new version goes into the deployment at 0% first, and is tested through the Worker’s URL. At each step above 0%, the probe also starts new objects until one runs the new version, so a version whose objects fail to start fails its step.
A ship turns the Worker’s workers.dev URL and preview URLs on, as
Cloudflare does by default, unless its config says workersDev: false;
plan says so when they’re off (~ workers.dev URL and preview URLs: off → on). On an existing Worker, a ship that fails turns them off again.
Behind Cloudflare Access
Section titled “Behind Cloudflare Access”If Cloudflare Access guards your Workers (say, one Access application over
your whole *.<subdomain>.workers.dev), every new Worker is private from
its first request, and so are ship’s smoke tests: Access sends them to its
login page. Give ship a service token that a Service Auth policy allows:
CF_ACCESS_CLIENT_ID=... CF_ACCESS_CLIENT_SECRET=... pnpm infra ship app.tsship sends the two as headers on every smoke-test request and every probe. Forget them, and the ship stops at once and undoes itself, saying why:
2.39s ✓ created Worker ship-access, live 3.84s ↩ deleted Worker ship-accessfailed: Cloudflare Access guards https://ship-access.<account>.workers.dev/, and asked the smoke test to log in: set CF_ACCESS_CLIENT_ID and CF_ACCESS_CLIENT_SECRET to a service token a Service Auth policy of its Access application allows, or ship with --no-smokeAll at once, or in steps
Section titled “All at once, or in steps”A version that passes its smoke test takes all the traffic at once: the
test ran on the version itself, before any user reached it. --steps
moves the traffic in steps instead, five seconds apart, smoke-testing at
each, for watching a version under real load first:
pnpm infra ship app.ts --steps 10,50,100They end at 100. Here are the steps as ship logs them, from ship’s own
fixture (with --steps 10,50,100 --no-smoke):
1.83s ✓ uploaded version 4 (5e1b7c2a), with no traffic 2.80s ✓ deployed 10% on version 4, 90% on the previous version 5.30s ✓ deployed 50% on version 4, 50% on the previous version 7.75s ✓ deployed 100% on version 4Canaries: steps judged on real traffic
Section titled “Canaries: steps judged on real traffic”A smoke test sends a few requests. A canary watches the real ones:
--canary 10,50 moves the traffic in those steps, and at each one, after
it has served its share for --bake (a minute by default), reads Workers
Analytics for how many requests each version served in the step and how
many failed. The new version fails the step, and the ship rolls back,
when it has at least 3 errors and its error rate is more than a point
above the previous version’s, or more than double it:
pnpm infra ship app.ts --canary 10,50 --bake 2mA version broken on one path, /boom, which its smoke test of / can’t
see, with traffic to that path (ship’s lab Worker, --canary 50 --bake 40s):
3.31s ✓ deployed 50% on version 7, 50% on the previous version 5.20s baking 50% for 40s76.64s ↩ rolled back to 100% on the previous version
failed: the canary at 50% failed: the new version 53 errors in 57 requests (92.98%), the previous 0 errors in 91 requests (0.00%): worseAnd a healthy one, which goes on:
4.71s baking 50% for 35s71.90s ✓ canary at 50%: the new version 0 errors in 60 requests (0.00%), the previous 0 errors in 60 requests (0.00%)72.54s ✓ deployed 100% on version 8Analytics lags the traffic it counts, by about half a minute in these
runs, so a step waits up to 90 seconds more for it. A step whose new
version served fewer than 50 requests is too quiet to judge: ship says so
and goes on, or, with --canary-strict, fails it. The token needs
Account Analytics: Read. Through a deployer, an app’s
canary (infra ship --via) is judged on what the deployer reads, with
its own token; a Worker shipped alone with ship --via takes no canary
yet.
Undone, on failure or Ctrl-C
Section titled “Undone, on failure or Ctrl-C”If anything fails, or you press Ctrl-C, the ship undoes what it did, in reverse:
- traffic goes back to the previous deployment, exactly as it was (unless someone else has deployed since),
- a Worker that didn’t exist before is deleted,
- resources this ship made are deleted,
- routes it took over go back to the Workers they served, and domains it added are removed.
Resources that existed before are never touched. And with infra, every Worker of an app ships in one scope, so a failure in the third Worker undoes the first two as well.
Ctrl-C halfway through a rollout in steps (ship’s own fixture, with
--steps 10,50,100):
2.53s ✓ deployed 10% on version 5, 90% on the previous version13.52s ✓ deployed 50% on version 5, 50% on the previous version14.21s ↩ rolled back to 100% on the previous version
interrupted, after undoing what it didA broken version never gets traffic: its test on its own preview URL fails first, after a minute of asking again if it answers 500.
2.05s ✓ uploaded version 7 (f9cc274d), with no traffic 2.61s GET / answered 500 this version is broken, on purpose; a new Worker's first minute can be its dependencies' warm-up, so asking again for up to 60s
failed: smoke test of https://f9cc274d-ship-hello.<account>.workers.dev/ failed: 500 this version is broken, on purposeWith infra, each failure, with its reason, goes into the app’s history
too (infra state), and so does a ship you interrupt.
--atomic: when a version can’t share traffic
Section titled “--atomic: when a version can’t share traffic”Cloudflare can’t split traffic between two versions with different Durable Object classes. So a version that adds, renames or removes one can’t be rolled out in steps, and the ship stops and says so (ship’s own fixture):
stopped: this version adds Tally (durable-object, sqlite), and Cloudflare can't split traffic between versions with different exports; ship it with --atomic to deploy it at 100% before its smoke test, rolled back if the test fails--atomic deploys it at 100% before its smoke test, as it can’t be
tested first, and still rolls it back if the test fails:
2.86s ✓ uploaded version 7 (0b8e43d1), with no traffic 3.21s version changes exports (+Tally (durable-object, sqlite)), so it goes out at 100% before its smoke test 3.73s ✓ deployed 100% on version 7infra check --account warns about this before you ship
(exports-changed). More in Durable Objects.
- Ship a Worker you already have: ship’s commands and options.
- Plan and ship: the same rollout, for an app declared in Effect.