---
title: Pipeline
description: Trunk-based delivery. Build once, then promote one image digest and one client bundle through dev, staging and prod.
sidebar:
  icon: workflow
---

Every merge to `main` is a release candidate. The pipeline builds it **once**: one server image, identified by its manifest digest, and one client bundle. It then releases that pair to dev, staging and prod, in that order. Each environment runs a rolling ECS update with the deployment circuit breaker and the 5xx-ratio alarm rollback from Task 1, then checks the result itself before it moves on.

## The pipeline

```mermaid
flowchart TB
  pr[Pull request] --> ci["ci.yml: quality gates, required check ci-ok"]
  ci -->|merge to main| build["deploy.yml build: one image digest, one client bundle"]
  build --> dev["dev: automatic"]
  dev --> staging["staging: automatic"]
  staging --> prod["prod: reviewer approval"]
  rb["rollback.yml: manual"] -.->|older SHA, same release steps| prod
```

| Workflow | Trigger | What it does |
|---|---|---|
| `ci.yml` | Pull request into `main` | Quality gates. One required check, `ci-ok`. See [Quality gates](/quality-gates). |
| `deploy.yml` | Push to `main` (not `infrastructure/**` or `docs/**`), or a manual run | Builds once, then calls `_release.yml` for dev, staging and prod. |
| `_release.yml` | Called by `deploy.yml` and `rollback.yml` | Puts one release into one environment. The only deploy implementation. |
| `rollback.yml` | Manual | Releases an older, known-good SHA through `_release.yml` and freezes deploys. See [Rollback](/rollback). |
| `unfreeze.yml` | Manual | Clears the freeze after the fix is on `main`. |
| `terraform.yml`, `_terraform.yml` | Pull request or push under `infrastructure/` | Plan on pull requests; plan, then apply of that same saved plan, on `main`. |

Every workflow starts with `permissions: {}` and gives each job only what it needs. `id-token: write` appears only on jobs that assume an AWS role. Every action is pinned to a full commit SHA. Every tool image (Trivy, gitleaks, tflint, actionlint, shellcheck, the Python base image) is pinned by digest.

## Build once

Each environment has its own AWS account, so each has its own ECR registry. `docker save` and `docker load` can change a digest, so the pipeline never uses them.

1. **Build an OCI archive**

    `scripts/ci/build-server-image.sh` runs `docker buildx build --target production --build-arg RELEASE_SHA=$GITHUB_SHA --provenance=false --sbom=false --output type=oci`. Without attestations the archive holds one image manifest, not an index. The script fails unless the build's digest equals the manifest digest in the archive's `index.json`. `RELEASE_SHA` becomes the `service.version` of every metric, span and log line, so the image reports its own release whichever environment runs it.

2. **Copy it into each account unchanged**

    `scripts/ci/push-image.sh` runs `skopeo copy --preserve-digests oci-archive:… docker://<repo>:<sha>`. skopeo fails rather than write a manifest with a different digest. The script then reads the digest back from ECR and fails on any difference.

3. **Deploy by digest**

    The task definition gets `repository@sha256:…`, never a tag. The tag (the commit SHA) exists only so that people can find the image.

:::success[Checked locally]
An archive built by `build-server-image.sh` and copied to a local `registry:2` with `skopeo copy --preserve-digests` kept its digest: `sha256:e8eabbfc…` before and after.
:::

The client bundle is built once too. The API base is relative (`/api`), so one bundle is correct in every environment. The build's only input is `VITE_RELEASE_SHA`, which goes into `<meta name="release">` in `index.html` so that the post-release check can read back which release CloudFront serves.

## One release, step by step

`_release.yml` runs one job in the target GitHub Environment. The steps that change what users reach come after every check.

**Deploy**

1. **Check the freeze flag**

    `freeze.sh check`. If `rollback.yml` froze this environment, stop with the reason.

2. **Bring the build into this account**

    Push the image (digest compared) and archive the bundle at `releases/<sha>/` in the site bucket. Nothing users reach changes yet.

3. **Check both halves exist**

    `check-release-artifacts.sh`: the digest is in ECR and `releases/<sha>/index.html` is in the bucket.

4. **Start the release record**

    A GitHub Deployment for this SHA, with the status `in_progress`.

5. **Register a task definition**

    The newest active revision of the family, with only the image changed, tagged `release-sha=<sha>`.

6. **Update the service and wait**

    Smoke traffic runs through CloudFront during the wait, so the alarm has data.

7. **Verify**

    The primary deployment must run the new revision with `rolloutState` `COMPLETED`.

8. **Smoke test**

    One document read and one WebSocket suggestions round trip, through the public URL.

9. **Publish the client**

    Assets first (one-year cache), then `index.html` (`no-cache`), then invalidate `/index.html`.

10. **Check CloudFront**

    `/` and `/index.html` serve this SHA, and every referenced asset loads.

11. **Record and report**

    Final status on the record, job summary, Slack message.

**Rollback**

1. **Set the freeze flag**

    Before any other change, so a deploy that queues behind the rollback stops.

2. **Check both halves still exist**

    The target's digest in ECR, and `releases/<sha>/index.html` in the bucket.

3. **Start the release record**

    Kind `rollback`, with the reason.

4. **Publish the old client first**

    So a newer client never talks to an older server.

5. **Register, update, wait, verify, smoke test**

    The same steps as a deploy, with the target's digest.

6. **Check CloudFront**

    `/` and `/index.html` serve the target SHA.

7. **Record and report**

    Then `rollback.yml` marks the releases it replaced `inactive`.

## Release records

Each release attempt in each environment is a GitHub Deployment with `task: release`, `ref` set to the release SHA, and a payload with the image digest, the kind and the reason. `scripts/ci/release-record.sh` writes them with `auto_inactive: false`, so the latest status is always the result of that release:

| Latest status | Meaning |
|---|---|
| `success` | Every step passed. A valid rollback target. |
| `failure` | A step failed after the first change. |
| `error` | The job was cancelled, for example by a rollback. |
| `inactive` | A later rollback replaced this release. |
| `in_progress` | Running, or the runner died. Not a rollback target. |

The jobs set `environment.deployment: false`, so GitHub does not add its own record. GitHub's record would carry the workflow's commit, which is wrong for a rollback.

## Concurrency

| Group | Used by | `cancel-in-progress` | Why |
|---|---|---|---|
| `deploy-<env>` | `deploy.yml` (each environment) | `false` | A deploy never stops another deploy halfway. GitHub's default queue keeps one pending run, and a newer run replaces it. On trunk the newer commit contains the older one, so nothing is lost. |
| `deploy-<env>` | `rollback.yml` | `true` | A rollback does not wait behind the deploy that may be causing the incident. Because it can stop a deploy at any step, it always sets both client and server. |
| `deploy-<env>` | `unfreeze.yml` | `false` | Waits behind a running rollback. |
| `terraform-<env>` | `terraform.yml` on `main` | `false` | Separate from deploys, so a rollback never cancels an apply. One group covers plan and apply together. |
| `ci-<pr>` | `ci.yml` | `true` | A new push makes the old run useless. |

:::note
`queue: max` (up to 100 pending runs, added May 2026) would release every intermediate commit in turn. The default `queue: single` is the choice here. The key is left out of the YAML because actionlint 1.7.12 does not know it yet.
:::

## Scripts

Each script does one step, uses `set -euo pipefail`, and takes its inputs from environment variables named in its header.

| Script | Step |
|---|---|
| `build-server-image.sh`, `push-image.sh` | Build once; copy into ECR, keeping the digest |
| `upload-client.sh`, `publish-client.sh`, `check-site.sh` | Archive the bundle; make it live; confirm through CloudFront |
| `check-release-artifacts.sh` | Stop before any change if the image or bundle is missing |
| `register-task-definition.sh`, `wait-for-service.sh`, `verify-deployment.sh` | ECS revision, rollout wait, rollout result |
| `generate-traffic.sh`, `smoke.py` | Alarm data during the wait; API and WebSocket smoke test |
| `freeze.sh`, `release-record.sh`, `resolve-rollback-target.sh` | Freeze flag; release history; rollback target |
| `notify-slack.sh` | Release result to Slack |
| `changed-paths.sh`, `terraform-plan.sh`, `terraform-apply.sh` | CI path filter; Terraform |

:::warning[Zero downtime is about requests, not data]
Rolling updates keep 100% of tasks serving during a release. The app still uses in-memory SQLite, so **every deploy and every rollback erases all saved documents**. See [Rollback](/rollback).
:::
