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.yml carries an image: (only the infrastructure services do), so a bare docker compose up -d builds 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-only or full; 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

  1. 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-')
  2. Roll one service at a time. --no-deps leaves the rest of the stack untouched; --pull always fetches 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; }
    done

    The compose health probes and their timings are in Deployment Guide › Health. The portal’s depends_on needs 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’s depends_on names canopy-security, canopy-identity’s issuer, healthy.

  3. 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 with CANOPY_<SVC>SKIP_MIGRATIONS=true, run the job first: canopy-manage migrate apply --service canopy-<svc> with CANOPY_MIGRATEDATABASE_URL set (Deployment Guide › Migrations).

  4. 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:

  1. Stage the new snap-{allotments,deductions,income-limits}-<yr>.json beside the old ones (the federal layer’s README.adoc; Policy currency runbook).

  2. cargo xtask policy audit --source federal must pass.

  3. Restart canopy-snap and confirm the boot inventory line snap parameter set loaded shows the new window (services/canopy-snap/src/main.rs).

  4. Emergency valve if the files cannot land in time: CANOPY_SNAP__ALLOW_EXPIRED_PARAM_SET=true serves the newest expired set — wrong benefits by design, ERROR-logged per use; remove it the moment the files land (accountable overrides).

Verify

  1. 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.env or cargo xtask dev status, never from a fixed list. canopy-web publishes no port: reach its /readyz through 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")"
    done

    A 503 body names the failing check (database, rabbitmq, outbox, a worker) in development; production suppresses the detail — read the service log.

  2. Smoke test one authenticated read against canopy-persons (GET /v1/persons is LIST_PERSONS in crates/canopy-contracts-persons/src/paths.rs; there is no /api prefix), with a canopy-identity token from canopy-cli, signed in with canopy login as 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"
  3. 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).

  4. On a devstack, cargo xtask test --integration against 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.

NOTE
History — this page replaced the earlier "Scaling & Deployment" runbook, which listed 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.
Edit this page · default