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
8 changes: 8 additions & 0 deletions .context/TECHSTACK.md
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,14 @@ 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-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`.
Logic in `scripts/cd-watch.mjs`; `/healthz` reads the commit baked into the image (`server/revision.ts`).
The last successful D2 SHA is read from a GitHub deployment (environment `c00-doop`) that D2's evidence job
writes on each confirmed deploy (typed JSON booleans, read back), reconciled with the D2 runs newer than the
record (a confirmed deploy without a record is `unknown`), and without a record a paginated scan of
`deploy-evidence` artifacts; unreadable history is `unknown` and fails visibly, never "nothing deployed".
- `.github/workflows/cla.yml` - CLA check (this is an AGPL-3.0 project with CLA-based
contribution).
- `.github/workflows/desktop.yml` / `desktop-release.yml` - Tauri desktop app CI and installer
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/cd-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ jobs:
timeout-minutes: 5
permissions:
contents: read
deployments: write
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -452,3 +453,11 @@ jobs:
name: deploy-evidence
path: deploy-evidence.json
if-no-files-found: error
# After the artifact, so a failed record never loses it: a confirmed deploy is also recorded as a GitHub
# deployment. That is the durable last successful D2 SHA the watchers (CHE-5550, C-7) read; neither artifact
# expiry nor a run of skipped slots can lose it.
- name: Record a confirmed deploy
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: node scripts/cd-watch.mjs record deploy-evidence.json
40 changes: 40 additions & 0 deletions .github/workflows/cd-freshness-watch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ci-policy: class=scheduled
name: CD freshness watch

# C-7.1 of the deploy train (CHE-5550, plan CHE-5474). D2 (`cd-deploy.yml`) runs at 06:17, 14:17 and 22:17 ICT; this
# watcher is its backup. Every 15 minutes it asks, in `scripts/cd-watch.mjs freshness`: is the last D2 slot 45 min
# old, is a qualified candidate ahead of the last successful D2 SHA, and does no D2 run exist since the slot? Then it
# sends one `schedule_backup` dispatch. At 90 min it fails this run with `::error::`. A failed D1 build is rerun once.
# The last successful D2 SHA is read from the deployment record D2 writes after each confirmed deploy (artifacts are the
# fallback), not from a run conclusion: a skipped D2 ends green. An unreadable history fails this run.
#
# The dispatch is made with the workflow token, so D2 sees `github-actions[bot]`, the one actor it admits for
# `schedule_backup`. It does nothing while repo variable DOOP_DEPLOY_TRAIN is not `on`.
on:
schedule:
- cron: '12,27,42,57 * * * *'
workflow_dispatch:

permissions:
contents: read
actions: write
deployments: read

# Deliberately no concurrency group and no self-hosted runner: a dead deploy runner or a stuck queue must not
# silence the alarm. Public repo: GitHub-hosted minutes are free.
jobs:
freshness:
if: github.repository == 'cheese-work/doop'
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
# Via env, never inlined into the script.
- name: Check D2 freshness
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
DOOP_DEPLOY_TRAIN: ${{ vars.DOOP_DEPLOY_TRAIN }}
run: node scripts/cd-watch.mjs freshness
39 changes: 39 additions & 0 deletions .github/workflows/cd-live-revision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ci-policy: class=scheduled
name: CD live revision

# C-7.2 of the deploy train (CHE-5550, plan CHE-5474). Every 15 minutes, on the gate runner (which is on the
# tailnet), `scripts/cd-watch.mjs live` reads `https://$DOOP_C00_HOST/healthz` and fails when the revision C00 serves
# is behind the last successful D2 SHA. `/healthz` answers `{ ok, revision }`; the revision is the DOOP_REVISION
# build arg of `image.yml`. The last successful D2 SHA comes from the deployment record D2 writes after each confirmed deploy (the `deploy-evidence`
# artifacts are the fallback); an unreadable history fails this run too.
#
# Read only: no deploy secret, no build, no write to C00. Schedule only. It does nothing while repo variable
# DOOP_DEPLOY_TRAIN is not `on`.
on:
schedule:
- cron: '7,22,37,52 * * * *'

permissions:
contents: read
actions: read
deployments: read

jobs:
live-revision:
if: github.repository == 'cheese-work/doop'
runs-on: [self-hosted, Linux, X64, cheese-x99-gate]
timeout-minutes: 10
steps:
# The full history: the live SHA is placed against the last deployed SHA with `git merge-base --is-ancestor`.
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
# Via env, never inlined into the script.
- name: Check the live revision
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
DOOP_DEPLOY_TRAIN: ${{ vars.DOOP_DEPLOY_TRAIN }}
DOOP_C00_HOST: ${{ vars.DOOP_C00_HOST }}
run: node scripts/cd-watch.mjs live
3 changes: 3 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ jobs:
tags: ${{ env.IMAGE }}:${{ github.sha }}
# The C00 readback compares this label with the SHA it deployed.
labels: org.opencontainers.image.revision=${{ github.sha }}
# /healthz reports it, and the live-revision watcher compares it with the last successful D2 (CHE-5550).
build-args: |
DOOP_REVISION=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
# The migration inventory D2's `admit` recomputes from the checked-out candidate (C-6).
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ COPY shared ./shared
COPY scripts/deploy-smoke.mjs ./scripts/deploy-smoke.mjs
COPY deploy/cd/smoke-routes.json ./deploy/cd/smoke-routes.json

# The commit this image was built from, read by /healthz (CHE-5550). Declared last so a new commit busts only this
# layer; image.yml passes it, and a local build without it reads `unknown`.
ARG DOOP_REVISION=unknown
RUN printf '%s\n' "$DOOP_REVISION" > /app/REVISION

EXPOSE 4400
HEALTHCHECK --interval=30s --timeout=5s CMD node -e "fetch('http://localhost:'+process.env.PORT+'/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
# the installed binary rather than npx: npm is not what resolves packages here
Expand Down
51 changes: 51 additions & 0 deletions deploy/cd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,64 @@ health, restart counts, delay, lock wait, and the read-back time, confirm time a
beside it. Values that are not the exact shape they should be are dropped. Tofu or c00-hermes-devops copies the
read-back values to CHE-2752.

## Watchers (S7, C-7)

Two scheduled workflows watch D2. Both do nothing (a clean skip, exit 0) while `DOOP_DEPLOY_TRAIN` is not `on`, so
they cost no alarm while the train is off, and both are scheduled from the merge of this slice, so they are seen
running before the switch can turn on. The last successful D2 SHA has four states, never a guess:
`known` (a SHA), `pending` (a D2 run under 3 h old is unfinished and may confirm any minute: only the SHA comparison waits: freshness still alarms at 90 min after the slot and live still needs a healthy `/healthz`), `none` (a proven first deployment: no D2 run exists, or every one was read and none confirmed) and
`unknown` (the history cannot be read). Where it comes from, in order:

1. The deployment record. The `evidence` job of D2 (`permissions: deployments: write`, after the artifact upload) runs
`node scripts/cd-watch.mjs record deploy-evidence.json` on a confirmed deploy: a GitHub deployment in environment
`c00-doop` at the candidate SHA (description `... (D2 run <id>, confirmed <UTC time>)`, `auto_merge` and `production_environment` sent as
JSON booleans), with a `success` status, read back before the step passes. A write that fails turns the D2 run red.
Neither artifact expiry nor any number of skipped D2 slots can lose it. The watchers read it with
`deployments: read`. Deploys are ordered by their confirmation time, never by run ID: runs queue independently, so
an older run can confirm after a newer one, and a run can be rerun days later. The record is not trusted alone: every
D2 run whose last activity (`updated_at`, which a rerun moves) is not before the record's confirmation is checked,
newest created first. A run with no evidence (green, failed or cancelled: a deploy can confirm and then lose its
evidence upload), or whose evidence confirms another SHA after the record (its record write failed), is `unknown`;
one that confirmed before the record is older and ignored. A run that ended before the record's confirmation is
not read. A run created over 30 days (GitHub's rerun limit) before the record ends the scan. A confirmed deploy
without a confirmation time cannot be ordered: the record step fails the D2 run.
2. Without a record: the `deploy-evidence` artifact (`outcome: confirmed`), the latest confirmation winning, up to
100 evidence reads (a skipped D2 ends green, so a run conclusion is not used). A run whose artifact is gone or
unreadable, a confirmed artifact with a bad SHA, or hitting the scan limit is `unknown`.

`unknown` fails visibly: the freshness watch alarms at once when a candidate exists, and the live watch fails. A
deployed candidate is never treated as overdue, and an unreachable `/healthz` never passes, because of missing history.
The decisions are pure functions in `scripts/cd-watch.mjs`, tested in `tests/cdWatch.test.ts`.

- `cd-freshness-watch.yml` (hosted, `12,27,42,57 * * * *`): the newest D2 slot is at least 45 min old, a qualified
candidate (`pickCandidate`: the newest `cheese/main` commit with a successful D1 push run) differs from the last
successful D2 SHA, and no D2 run was created since the slot: one `workflow_dispatch` of `cd-deploy.yml` with
`mode=train`, `schedule_backup=true`, made with the workflow token (`github-actions[bot]`, the one actor D2 admits
for it). Once a D2 run exists there is no second dispatch. At 90 min with a candidate still ahead the run fails with
`::error::`, whether or not a D2 run exists (a skipped, suspended or forward-only run left C00 behind all the same).
A failed D1 run on `cheese/main` is rerun once (`gh run rerun --failed` while `run_attempt` is 1).
- `cd-live-revision.yml` (on `cheese-x99-gate`, schedule only, `7,22,37,52 * * * *`): reads
`https://$DOOP_C00_HOST/healthz` over the tailnet and fails when the revision is behind the last successful D2 SHA.
Ahead is fine (a deploy whose evidence is not written yet); a diverged, missing, malformed or `unknown` revision
fails. With a proven `none` (no successful D2 yet) there is no SHA to compare with, but `/healthz` must still answer
`ok: true` with a 40-hex revision; with `unknown` it fails.
- `/healthz` answers `{ ok, revision }`. `image.yml` passes `DOOP_REVISION=${{ github.sha }}` as a build arg; the
`Dockerfile` writes it to `/app/REVISION` (last layer) and `server/revision.ts` reads it once at start. A build
without the arg, or a dev run, reports `unknown`.

Read-back before the switch: before `DOOP_DEPLOY_TRAIN` is set to `on`, each watcher shows a green scheduled run on
the Actions page (`gh run list --workflow cd-freshness-watch.yml --event schedule`, and the same for
`cd-live-revision.yml`) from after the merge of this slice. Repo variable `DOOP_C00_HOST` (the doop host name on
C00's tailnet, no scheme) must be set before the switch too: the live watcher fails when it is `on` and the host is unset.

## Prerequisites (set once; not in this repo)

| Where | Name | Value |
| ------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Runner | label `cheese-c00-deploy` | self-hosted runner on C00 with Docker and `docker compose` (node 22 comes from `actions/setup-node`; the runner needs egress to download it), in runner group `c00-deploy` (D1), limited to `cheese-work/doop` and `cheese-work/multica` |
| Repo variable | `C00_DOOP_COMPOSE_DIR` | optional; default `/home/congvc/.local/share/doop` (`compose.yaml`, service `app`, its `.env`) |
| Repo variable | `C00_DEPLOY_AUTHORIZERS` | extra logins, e.g. the agent-merge identity |
| Repo variable | `DOOP_C00_HOST` | doop's host name on C00's tailnet, no scheme; read by `cd-live-revision.yml` |
| Repo variable | `MAIN_RED_PAUSED` | empty, or a reason to pause |
| Environment | `c00-readback-delay` | on `cheese-work/doop`, with a **15 minute wait timer** and no secret. Created by hand before the C-11 drill: GitHub creates a missing environment with no timer, and `c00.sh confirm` then refuses (delay not honoured) |
| Environment | `doop-deploy-marker` | on `cheese-work/doop`; holds the marker App's key. The three C00 jobs run in it; no hosted job does |
Expand Down
Loading
Loading