Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .context/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ confirm, and written `suspended:*` (never clear) by recovery, drill and rollback
and a GitHub App token from environment `doop-deploy-marker`. Setup and rules:
[`deploy/cd/README.md`](../deploy/cd/README.md).

Lifting a suspension is `cd-lift.yml` (S3b): dispatch with the id of an approved Multica decision; it checks the
decision against the standing marker, proves quiescence and health on C00, and writes `clear:*` with evidence.
It never turns the train on.

## Desktop app (Tauri: macOS DMG + Windows NSIS installer + Linux AppImage/.deb/.rpm)

Driven by `.github/workflows/desktop-release.yml`; every desktop job shares the toolchain setup
Expand Down
5 changes: 5 additions & 0 deletions .context/TECHSTACK.md
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,11 @@ data-doop-webfonts>` for the roster families the frame names and does not load i
- `.github/workflows/cd-deploy.yml` - D2, the only workflow that deploys to C00: schedule (3 a day) and
dispatch, off unless repo variable `DOOP_DEPLOY_TRAIN` is `on`; the `DOOP_DEPLOY_SUSPENDED` marker is written
only by `scripts/deploy-marker.mjs`. See `deploy/cd/README.md`.
- `.github/workflows/cd-lift.yml` - S3b, the audited lift: dispatch only (`decision_id`), allowlisted dispatcher,
C00 runner under the deploy lock. Writes `clear:*` only for an approved `doop.deploy_lift` Multica decision whose
`marker_value` equals the standing marker, with quiescence and `/healthz` proven and the decision and marker
re-read before the write; evidence in `lift-evidence.json`. Logic in `scripts/deploy-lift.mjs`
(`c00.sh lift` supplies the C00 facts). Never touches `DOOP_DEPLOY_TRAIN`.
- `.github/workflows/cd-freshness-watch.yml` and `cd-live-revision.yml` - the two D2 watchers (every 15 min):
a backup `schedule_backup` dispatch when D2 is 45 min late (alarm at 90 min), and a check that C00's
`/healthz` `revision` is not behind the last successful D2 SHA. Both idle while `DOOP_DEPLOY_TRAIN` is not `on`.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cd-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ name: CD deploy
# The suspension marker (repo variable DOOP_DEPLOY_SUSPENDED, CHE-5545, plan C-10) is written only by the three
# C00 jobs, with scripts/deploy-marker.mjs: a train run arms it before its first change and only a passing
# confirm of that same run restores it; recovery and drill runs, and a rollback, write `suspended:*` and never
# `clear:*`. Every failure leaves it armed or suspended, which stops the train. Lifting is S3b.
# `clear:*`. Every failure leaves it armed or suspended, which stops the train. Lifting is cd-lift.yml.
# The train ships OFF: the repository variable DOOP_DEPLOY_TRAIN is absent or not 'on', so a scheduled run
# ends at `resolve` as a clean skip.
# Schedule: 23:17, 07:17 and 15:17 UTC = 06:17, 14:17 and 22:17 ICT.
Expand Down Expand Up @@ -392,7 +392,7 @@ jobs:
repositories: doop
permission-variables: write
# Whatever the rollback did, even if it failed: this run's armed value becomes suspended (C-10.3). Only a
# lift (S3b) clears it. Not after a refused check, where the marker is no longer this run's own.
# lift (cd-lift.yml) clears it. Not after a refused check, where the marker is no longer this run's own.
- name: Suspend the marker
if: ${{ !cancelled() && steps.rollback.outputs.go == 'true' }}
env:
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/cd-lift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# ci-policy: class=deploy
name: CD lift

# S3b of the deploy train (CHE-5551, plan CHE-5474 C-10.6 and C-10.7): the audited lift. It is the only way from
# `armed:*` or `suspended:*` back to `clear:*`, and nothing but this workflow writes a lift.
#
# Dispatch only, one input: the id of a Multica decision. The dispatcher (and the login that triggered the run)
# must be in vars.DOOP_LIFT_DISPATCHERS. On the C00 runner, under the host lock, scripts/deploy-lift.mjs refuses
# unless ALL hold:
# - the decision is action type doop.deploy_lift (v1), state approved, approved by vars.DOOP_LIFT_APPROVER_ID
# (Cheese), and not withdrawn, rejected, revoked or expired;
# - its marker_value param equals the marker that stands now, byte for byte, and its repo param is this repository;
# - migration quiescence is proven (C-8.8), /healthz answers 200, and the running digest and revision label read;
# - right before the write, still under the lock, the decision and the marker are read again and still hold.
# Then it writes `clear:<nonce>:<this run id>`, reads it back, and records the lifter, decision, approver, health,
# digest, revision and ICT times in the run summary and lift-evidence.json. A refusal leaves the marker unchanged and
# fails the run. No step is a human-typed command.
#
# The decision is read from the Multica server over the tailnet with a scoped read-only token (environment
# doop-lift), so the C00 runner must reach that server. The marker is a repository variable that only the GitHub
# App can write, so environment doop-lift also holds the App's id and key (DOOP_MARKER_APP_ID, DOOP_MARKER_APP_KEY).
# A dispatch from any branch but the default one is skipped: a branch must not run its own lift script.
# The train ships OFF and this workflow does not touch the switch (DOOP_DEPLOY_TRAIN).
on:
workflow_dispatch:
inputs:
decision_id:
description: Id of the approved Multica decision (action doop.deploy_lift) that names the marker to lift
type: string
required: true

permissions:
contents: read

jobs:
lift:
if: ${{ github.repository == 'cheese-work/doop' && github.ref == 'refs/heads/cheese/main' }}
runs-on: [self-hosted, cheese-c00-deploy]
timeout-minutes: 20
environment: doop-lift
permissions:
contents: read
# One C00 job at a time, shared with deploy, readback-confirm and rollback; a started lift is never cancelled.
concurrency:
group: c00-deploy-doop
cancel-in-progress: false
env:
C00_COMPOSE_DIR: ${{ vars.C00_DOOP_COMPOSE_DIR || '/home/congvc/.local/share/doop' }}
# Empty: c00.sh finds the compose project's `db` service. Set it to name the live Postgres container.
C00_PG_CONTAINER: ${{ vars.C00_DOOP_PG_CONTAINER }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: 22
# First, before any secret is read or minted: a login outside the allowlist ends the run here.
- name: Admit the dispatcher
env:
ACTOR: ${{ github.actor }}
TRIGGER: ${{ github.triggering_actor }}
DISPATCHERS: ${{ vars.DOOP_LIFT_DISPATCHERS }}
run: node scripts/deploy-lift.mjs admit
# The marker is a repository variable; `github.token` cannot write one, so a GitHub App token does.
- name: Mint the marker token
id: app
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ vars.DOOP_MARKER_APP_ID }}
private-key: ${{ secrets.DOOP_MARKER_APP_KEY }}
repositories: doop
permission-variables: write
# C-5: every C00 job removes the compat sandboxes first. A failed sweep fails the run before the lift.
- name: Sweep the compat sandboxes
run: bash deploy/cd/c00.sh sweep
# One step, all under the C00 flock: quiescence, then digest, revision label and health, then the decision and
# the marker read, decided, read again, and written. Anything missing refuses and leaves the marker as it was.
- name: Lift on C00
env:
GH_TOKEN: ${{ steps.app.outputs.token }}
REPO: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
LIFTER: ${{ github.triggering_actor }}
DECISION_ID: ${{ inputs.decision_id }}
APPROVER_ID: ${{ vars.DOOP_LIFT_APPROVER_ID }}
MULTICA_SERVER_URL: ${{ secrets.DOOP_LIFT_MULTICA_SERVER_URL }}
MULTICA_WORKSPACE_ID: ${{ secrets.DOOP_LIFT_MULTICA_WORKSPACE_ID }}
DECISION_READ_TOKEN: ${{ secrets.DOOP_LIFT_DECISION_READ_TOKEN }}
# What the app answers on C00 itself; set the variable when the published port is not 4400.
HEALTHZ_URL: ${{ vars.C00_DOOP_HEALTHZ_URL || 'http://127.0.0.1:4400/healthz' }}
run: bash deploy/cd/c00.sh lift
- name: Upload the lift evidence
if: ${{ always() }}
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
with:
name: lift-evidence
path: lift-evidence.json
if-no-files-found: warn
44 changes: 38 additions & 6 deletions deploy/cd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ a skip too. This slice approves no deploy: nothing sets the switch to `on`, and

Repo variable `DOOP_DEPLOY_SUSPENDED` is the one thing that lets a train run. Its value is one of:

| Value | Meaning |
| ------------------------------------------- | --------------------------------------------- |
| `clear:<nonce>:<lift run id or restore>` | the train may run |
| `armed:<nonce>:<run id>:<sha>` | a train run is changing C00 |
| `suspended:<nonce>:<run id>:<sha>:<reason>` | stopped until a lift (slice S3b) writes clear |
| Value | Meaning |
| ------------------------------------------- | ----------------------------------------------------------- |
| `clear:<nonce>:<lift run id or restore>` | the train may run |
| `armed:<nonce>:<run id>:<sha>` | a train run is changing C00 |
| `suspended:<nonce>:<run id>:<sha>:<reason>` | stopped until the audited lift (`cd-lift.yml`) writes clear |

The nonce is 128 random bits. Absent, unreadable or any other shape reads as suspended; a prefix match is not
enough. `scripts/deploy-marker.mjs` is the only writer. Every write reads the variable, checks it is the
Expand All @@ -46,7 +46,39 @@ value the writer expects, writes, and reads it back; a write it cannot prove fai
over its own `armed:*`, whatever the rollback itself did.
- **Reading is read only.** `decide` and every check read the marker and never write it.

Every failure leaves the marker `armed` or `suspended`, so the train stops until a lift. Lifting is S3b.
Every failure leaves the marker `armed` or `suspended`, so the train stops until a lift. Lifting is `cd-lift.yml` (below).

### The audited lift (`cd-lift.yml`, S3b, C-10.6 and C-10.7)

The only way from `armed:*` or `suspended:*` back to `clear:*`. Dispatch only, one input: `decision_id`, the id of
a Multica decision. No step is a human-typed command.

1. The dispatcher and the triggering login must both be in repo variable `DOOP_LIFT_DISPATCHERS` (checked first,
before any secret is read). The job runs only on `cheese/main`, in environment `doop-lift`, on the C00 runner,
in concurrency group `c00-deploy-doop`, and `c00.sh lift` takes the host lock.
2. Under the lock it refuses unless **all** hold, and a refusal leaves the marker as it was:
- the decision is action `doop.deploy_lift` v1, `approved`, by `vars.DOOP_LIFT_APPROVER_ID` (Cheese), not
withdrawn, rejected, revoked or expired; unreadable or unknown is a refusal;
- its `marker_value` equals the marker that stands now, byte for byte, and its `repo` is `cheese-work/doop`;
- migration quiescence is proven (C-8.8), `/healthz` answers 200, and the running digest and revision label read;
- the decision and the marker are read again immediately before the write and still hold (a marker that
changed, or a decision revoked, during the lift refuses).
3. It writes `clear:<nonce>:<lift run id>`, reads it back, and records lifter, decision id, approver, health, digest,
revision and ICT times in the run summary and the `lift-evidence` artifact (`lift-evidence.json`, outcome
`lifted`, `refused` or `failed`; `failed` means the write could not be read back, so check the marker by hand).
Two lifts at once serialize on the lock; the second finds the marker changed and is refused.

The lift never reads or writes `DOOP_DEPLOY_TRAIN`: the train stays off until Cheese turns it on.

| Where | Name | Value |
| -------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| Environment | `doop-lift` | holds the secrets below; restrict deployment branches to `cheese/main` |
| Env secret | `DOOP_LIFT_DECISION_READ_TOKEN` | read-only token for `GET /api/decisions/{id}/state` |
| Env secret | `DOOP_LIFT_MULTICA_SERVER_URL`, `..._WORKSPACE_ID` | the Multica server (tailnet only, so the C00 runner must reach it) and its workspace |
| Env var/secret | `DOOP_MARKER_APP_ID`, `DOOP_MARKER_APP_KEY` | the same marker App as D2: copy both into `doop-lift`, since a job takes one environment |
| Repo variable | `DOOP_LIFT_DISPATCHERS` | logins that may dispatch a lift |
| Repo variable | `DOOP_LIFT_APPROVER_ID` | Cheese's Multica member id; the decision's approver must equal it |
| Repo variable | `C00_DOOP_HEALTHZ_URL` | optional; default `http://127.0.0.1:4400/healthz` (what the app answers on C00 itself) |

### Adoption of the 11 Nov failure (one write, by an admin)

Expand Down
27 changes: 26 additions & 1 deletion deploy/cd/c00.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
# c00.sh guard refuse (exit 1) while an earlier compat migration's quiescence is unproven; re-proves the three
# facts and clears the guard when they hold. apply, rollback and sweep run it first; the lift
# job calls it. `guard-set run mig db user dbname app` writes it (compat-sandbox.mjs does).
# c00.sh lift the C00 half of cd-lift.yml (CHE-5551, C-10.7): refuse while a compat guard holds, take the host
# lock, prove migration quiescence, read the running digest, revision label and container
# health, and run scripts/deploy-lift.mjs lift under the same lock with those facts. That script
# decides, re-reads the decision and the marker right before the write, and writes `clear:*`.
# Unproven quiescence does not stop here: the script is told and records the refusal.
# c00.sh sweep remove every doop.compat.run resource (containers, networks, volumes), read back
# zero, print df before and after. Needs no compose dir and no deploy ref (CHE-5474 C-8.5d).
#
Expand Down Expand Up @@ -422,6 +427,26 @@ case $cmd in
fi
;;

lift)
guard_check
take_lock
# Under the lock: the three C-8.8 facts (in a subshell, so a refusal is handed on rather than exiting), then what
# C00 runs. A read that fails leaves its fact empty, which the lift script refuses.
if ( require_quiescent ) >&2; then LIFT_QUIESCENT=true; else LIFT_QUIESCENT=false; fi
img=$(docker inspect --format '{{.Image}}' "$container" 2>/dev/null) || img=
LIFT_DIGEST=
LIFT_REVISION=
if [ -n "$img" ]; then
LIFT_DIGEST=$(docker image inspect --format '{{range .RepoDigests}}{{println .}}{{end}}' "$img" 2>/dev/null |
sed -n 's/.*@\(sha256:[0-9a-f]\{64\}\)$/\1/p' | head -n 1) || LIFT_DIGEST=
LIFT_REVISION=$(docker image inspect --format '{{index .Config.Labels "org.opencontainers.image.revision"}}' "$img" 2>/dev/null) || LIFT_REVISION=
fi
LIFT_CONTAINER_HEALTH=$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$container" 2>/dev/null) || LIFT_CONTAINER_HEALTH=
export LIFT_QUIESCENT LIFT_DIGEST LIFT_REVISION LIFT_CONTAINER_HEALTH
echo "lift facts: quiescent=$LIFT_QUIESCENT digest=${LIFT_DIGEST:-unknown} revision=${LIFT_REVISION:-unknown} container=${LIFT_CONTAINER_HEALTH:-unknown}"
node "$here/../../scripts/deploy-lift.mjs" lift
;;

quiescence)
require_quiescent
echo "quiescent: no migrate container running, no migrate session, advisory key free"
Expand Down Expand Up @@ -449,5 +474,5 @@ case $cmd in
echo "sweep ok: containers=0 networks=0 volumes=0"
;;

*) die "usage: c00.sh apply|readback|confirm|rollback|quiescence|sweep|guard|guard-set" ;;
*) die "usage: c00.sh apply|readback|confirm|rollback|quiescence|lift|sweep|guard|guard-set" ;;
esac
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default tseslint.config(
],
languageOptions: {
globals: Object.fromEntries(
'process console Buffer URL fetch setTimeout clearTimeout setInterval clearInterval'
'process console Buffer URL AbortSignal fetch setTimeout clearTimeout setInterval clearInterval'
.split(' ')
.map((g) => [g, 'readonly']),
),
Expand Down
Loading
Loading