Rolling deploy & rollback
For an operator deploying a promoted build, or rolling one back. Topology, profiles, the database inventory and the health contract are in Deployment Guide; variable names in Configuration Reference; ports in Services. The devstack lifecycle (cargo xtask dev …) is not a deployment tool.
Preconditions
-
The build has been promoted (ADR-040): an immutable
:<short-sha>exists for both the shared service image and/portal. Prefer the short SHA over:<tag>or:latest— it is what promotion minted and what rollback needs. -
The prebuilt override is active in the shell that runs every command below. No canopy application service in
docker-compose.ymlcarries animage:(only the infrastructure services do), so a baredocker compose up -dbuilds them from source and never deploys an artifact:export COMPOSE_FILE=docker-compose.yml:docker-compose.prebuilt.yml export CANOPY_PREBUILT_SERVICE_IMAGE="${CI_REGISTRY_IMAGE:?}:${IMAGE_TAG:?}" export CANOPY_PREBUILT_PORTAL_IMAGE="${CI_REGISTRY_IMAGE:?}/portal:${IMAGE_TAG:?}" export CANOPY_PREBUILT_CONFIG_FETCH_IMAGE="${CI_REGISTRY_IMAGE:?}/config-fetch:${IMAGE_TAG:?}"All three image variables must be set even for a single-service roll — the override interpolates the whole file and
:?fails loud otherwise. -
The active profile is known (
snap-only,tanf-only,medicaid-chip,caps-only,wic-onlyorfull; Deployment Guide › Profiles) and every secret and variable the new build needs is already delivered to the environment (fail-closed checklist). -
A pre-deploy backup exists if the release carries migrations: migrations are forward-only, so the way back is point-in-time recovery (Backup & Restore).
Steps
-
Derive the service list from the active profile instead of maintaining one by hand — a hand-written list is how caps, wic, exchange and the portal get left on the old image:
PROFILE="${PROFILE:-full}" mapfile -t SERVICES < <(docker compose --profile "$PROFILE" config --services | grep '^canopy-') -
Roll one service at a time.
--no-depsleaves the rest of the stack untouched;--pull alwaysfetches the new ref:for SERVICE in "${SERVICES[@]}"; do docker compose --profile "$PROFILE" up -d --no-deps --pull always "$SERVICE" CID=$(docker compose ps -q "$SERVICE" | head -1) for _ in $(seq 1 60); do STATUS=$(docker inspect --format='{{.State.Health.Status}}' "$CID" 2>/dev/null || echo starting) [ "$STATUS" = healthy ] && break sleep 5 done [ "$STATUS" = healthy ] || { echo "ABORT: $SERVICE never became healthy"; exit 1; } doneThe compose health probes and their timings are in Deployment Guide › Health. The portal’s
depends_onneeds redis-sessions, canopy-applications, canopy-security, canopy-verification, canopy-persons and canopy-notices healthy, so roll it last; compose file order already does. Every other canopy service’sdepends_onnames canopy-security, canopy-identity’s issuer, healthy. -
Each service applies its own migrations at boot before it reports healthy (
crates/canopy-api/src/bootstrap.rs). In a deployment that runs the runtime withCANOPY_<SVC>SKIP_MIGRATIONS=true, run the job first:canopy-manage migrate apply --service canopy-<svc>withCANOPY_MIGRATEDATABASE_URLset (Deployment Guide › Migrations). -
Only after the whole fleet runs the new build, flip any emission gate the release introduced (next section).
Ending worker sessions (canopy-web)
Worker sessions live in canopy-web’s own database (web_session; canopy-web Data Model). To sign every worker out (a security incident, a release whose notes require it), run the store’s operator end until it returns no rows; each run ends at most 500 sessions, waits out any row a request briefly holds (so an empty run means none is left), and logs each one in web_session_end as operator:
WITH batch AS MATERIALIZED (
SELECT id FROM web_session ORDER BY id LIMIT 500 FOR UPDATE
), gone AS (
DELETE FROM web_session
WHERE id IN (SELECT id FROM batch)
RETURNING id, token_hash, record, created_at
), logged AS (
INSERT INTO web_session_end (session_id, kind, token_hash, subject, created_at, reason)
SELECT id, 'web', token_hash, record ->> 'sub', created_at, 'operator' FROM gone
)
SELECT id FROM gone;
Never TRUNCATE web_session or a bare DELETE: the end must be logged, and a sign-in completing afterwards is refused only when the session it replaces is recorded as ended by an operator. An end is final under replication only with synchronous commit (Deployment Guide › Worker sessions). One worker’s sessions end the same way with WHERE record →> 'sub' = …, the worker’s canopy subject (Worker Program Scope — Cutover & Operations (#1515 / ADR-044)).
The release that introduces this store (#2518) needs every canopy-web replica stopped before it deploys; its upgrade note is in Deployment Guide › Worker-session store upgrade.
Signed-field emission gates (ADR-028, verifier-tolerant-first)
A release that adds fields to the signed SignableDetermination ships them tolerant-first: the struct lands fleet-wide with emission behind a default-off gate, and the gate flips only after every verifier — canopy-eligibility above all — runs the tolerant build. An old verifier reconstructing canonical bytes without the new fields would quarantine every valid determination minted with them. Roll order within a deploy therefore does not matter; the gate flip after the roll does.
Current gate: CANOPY_SNAP__EMIT_POLICY_ATTESTATION (services/canopy-snap/src/config.rs) binds policy_target and evaluated_as_of into SNAP envelopes. Config default false; the devstack sets true (single atomic deploy). Flip it, then restart canopy-snap. Rolling canopy-eligibility back to a build without the fields requires flipping it off first.
Parameter-set cutover check (every October 1)
canopy-snap fails determinations closed (422 params_unstaged) when no snap-cola parameter set is in force at the evaluation date. Before each federal fiscal year:
-
Stage the new
snap-{allotments,deductions,income-limits}-<yr>.jsonbeside the old ones (the federal layer’sREADME.adoc; Policy currency runbook). -
cargo xtask policy audit --source federalmust pass. -
Restart canopy-snap and confirm the boot inventory line
snap parameter set loadedshows the new window (services/canopy-snap/src/main.rs). -
Emergency valve if the files cannot land in time:
CANOPY_SNAP__ALLOW_EXPIRED_PARAM_SET=trueserves the newest expired set — wrong benefits by design,ERROR-logged per use; remove it the moment the files land (accountable overrides).
Verify
-
Every API service answers 200 on
/readyz(the portal on/readyz). Host ports are whatever the deployment maps; on a devstack read them from.ports.envorcargo xtask dev status, never from a fixed list. canopy-web publishes no port: reach its/readyzthrough the ingress at its public origin (https://<origin>/readyz), and leave it out of this loop:for SERVICE in "${SERVICES[@]}"; do PORT=$(docker compose port "$SERVICE" "$(docker compose config --format json | jq -r ".services[\"$SERVICE\"].ports[0].target")" | cut -d: -f2) printf '%-22s %s\n' "$SERVICE" "$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:${PORT}/readyz")" doneA 503 body names the failing check (
database,rabbitmq,outbox, a worker) in development; production suppresses the detail — read the service log. -
Smoke test one authenticated read against canopy-persons (
GET /v1/personsisLIST_PERSONSincrates/canopy-contracts-persons/src/paths.rs; there is no/apiprefix), with a canopy-identity token from canopy-cli, signed in withcanopy loginas a worker holding a reader role (canopy CLI Reference):TOKEN=$(canopy --profile "${CANOPY_PROFILE:?}" token canopy-persons) curl -s -o /dev/null -w '%{http_code}\n' -H "Authorization: Bearer ${TOKEN:?}" \ "http://localhost:$(docker compose port canopy-persons 8002 | cut -d: -f2)/v1/persons" -
A worker signs in at canopy-web’s public origin, past the sign-in notice, and case search returns results; the RabbitMQ management UI shows consumers on every queue; canopy-security is persisting audit events (
GET /v1/security/chain/status, canopy-security API Reference). -
On a devstack,
cargo xtask test --integrationagainst the running stack is the full check (Testing).
Rollback
Refs are immutable per commit: rollback is a redeploy of the previous known-good :<short-sha>, never a restart hoping the old image is still cached.
-
One service — with the export block active, override the service image and re-run the single-service roll:
CANOPY_PREBUILT_SERVICE_IMAGE="${CI_REGISTRY_IMAGE:?}:<previous-short-sha>" \ docker compose --profile "$PROFILE" up -d --no-deps --pull always canopy-snap -
Whole stack — set both image variables to the previous short SHA and repeat the roll loop.
-
Migrations — a migration that shipped with the failed release is not reversed by redeploying the old binary (ADR-016); if it destroyed data, follow the PITR procedure in Backup & Restore. A compatible additive migration can stay.
-
Emission gates — flip the gate off before rolling a verifier back (above).
Re-run Verify after any rollback.
isolated-db as a start profile and 30xx host ports, neither of which the stack has; the ADR-040 image-reference and emission-gate sections were carried over unchanged.