broker auto-deploy: the .forgejo rail (ci.yml publish-broker + broker-deploy.yml) — protected-path half of #688 #689

Closed
opened 2026-08-23 04:22:58 +00:00 by matou-build-agent · 1 comment

Why (protected path — filed from #688 by a Sandcastle worker)

#688 asks the broker to ride the ADR 0185 auto-deploy rail. Two of its
deliverables live under .forgejo/workflows/, which is a protected path
(rule 9 / #445): a worker that edits it has the change rolled back and the run
failed loud. So the worker landed everything else for #688 — the install leg
scripts/broker/idss-broker-install.sh (offline-tested,
scripts/tests/broker-install-test.sh), the broker/README.md runbook, and the
docs/GOTCHAS.md #59 entry — and files the .forgejo/ half here for a session
to apply (ADR 0174: a .forgejo/ machinery change needs an interactive
session's standing).

The install leg is already merged and proven: a session only needs to add the
two workflow pieces below and confirm one real publish+deploy.

Deliverable 1 — CI publishes the broker

Add a publish-broker job to .forgejo/workflows/ci.yml, mirroring the existing
publish (agent) job: on a push to main whose range touched broker/** (or
go.mod/go.sum), build ourcloud-broker and PUT it to the Forgejo generic
registry as idss-broker/<fullsha>/ourcloud-broker-x86_64 (+ .sha256 + a
RELEASE file), idempotent on 409. Uses secrets.REGISTRY_FORGEJO_TOKEN (the
swarm token has no write:package scope — see the publish job's comment).

Proposed job (starting point — match the publish job's PATH/nix idiom):

  publish-broker:
    needs: seam
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    runs-on: matou-workstation
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - name: Publish broker binary if broker/** changed
        env:
          FORGEJO_TOKEN: ${{ secrets.REGISTRY_FORGEJO_TOKEN }}
          FORGEJO_SERVER: ${{ github.server_url }}
          GIT_SHA: ${{ github.sha }}
          GIT_BASE: ${{ github.event.before }}
        run: |
          set -euo pipefail
          export PATH="/nix/var/nix/profiles/default/bin:$PATH"
          base="${GIT_BASE:-HEAD^}"; sha="${GIT_SHA:-HEAD}"; full="$(git rev-parse "$sha")"
          if ! git diff --name-only "$base" "$full" | grep -Eq '^(broker/|go\.mod|go\.sum)'; then
            echo "publish-broker: no broker-affecting change in ${base}..${full:0:12} — nothing to publish"; exit 0
          fi
          server="${FORGEJO_SERVER:-https://git.matou.nz}"; owner=Matou; package=idss-broker
          work="$(mktemp -d)"; trap 'rm -rf "$work"' EXIT; bin="$work/ourcloud-broker-x86_64"
          nix develop --extra-experimental-features 'nix-command flakes' --command bash -c \
            "cd broker && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -o '$bin' ./cmd/broker"
          sum="$(cd "$work" && sha256sum ourcloud-broker-x86_64 | awk '{print $1}')"
          printf '%s  ourcloud-broker-x86_64\n' "$sum" > "$work/ourcloud-broker-x86_64.sha256"
          printf '%s\n' "$full" > "$work/RELEASE"
          put() { local c; c="$(curl -sS -o /dev/null -w '%{http_code}' -H "Authorization: token $FORGEJO_TOKEN" --upload-file "$1" "$server/api/packages/$owner/generic/$package/$full/$2")"
            case "$c" in 200|201|204) echo "uploaded $2 ($c)";; 409) echo "$2 already present ($c)";; *) echo "FAILED $2 -> $c" >&2; return 1;; esac; }
          put "$bin" ourcloud-broker-x86_64
          put "$work/ourcloud-broker-x86_64.sha256" ourcloud-broker-x86_64.sha256
          put "$work/RELEASE" RELEASE
          echo "publish-broker: idss-broker@${full:0:12} published (sha256 $sum)"

Deliverable 3 — the deploy workflow

Add .forgejo/workflows/broker-deploy.yml on the matou-workstation runner (on
the Netbird mesh): workflow_dispatch with a sha input, and an automatic run
after CI's publish job on main — ssh deploy@100.98.48.68 sudo /usr/local/sbin/idss-broker-install <sha>, key = secrets.BROKER_DEPLOY_SSH_KEY
(a NEW deploy user's key, NOT dev).

Starting point:

name: broker-deploy
on:
  workflow_dispatch:
    inputs:
      sha: { description: full git sha CI published the broker under, required: true }
  workflow_run:
    workflows: [ci]
    types: [completed]
    branches: [main]
jobs:
  deploy:
    runs-on: matou-workstation
    timeout-minutes: 15
    if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
    steps:
      - name: Resolve sha
        id: sha
        run: |
          if [ "${{ github.event_name }}" = workflow_dispatch ]; then s="${{ github.event.inputs.sha }}"; else s="${{ github.event.workflow_run.head_sha }}"; fi
          echo "sha=$s" >> "$GITHUB_OUTPUT"
      - name: Skip if this sha was not published (docs-only push, etc.)
        id: pub
        run: |
          code="$(curl -sS -o /dev/null -w '%{http_code}' \
            https://git.matou.nz/api/packages/Matou/generic/idss-broker/${{ steps.sha.outputs.sha }}/ourcloud-broker-x86_64)"
          if [ "$code" = 200 ]; then echo "go=1" >> "$GITHUB_OUTPUT"; else echo "publish-broker skipped this sha ($code) — nothing to deploy"; echo "go=0" >> "$GITHUB_OUTPUT"; fi
      - name: Deploy
        if: steps.pub.outputs.go == '1'
        run: |
          install -d -m700 ~/.ssh
          printf '%s\n' "${{ secrets.BROKER_DEPLOY_SSH_KEY }}" > ~/.ssh/idss_broker_deploy
          chmod 600 ~/.ssh/idss_broker_deploy
          ssh -i ~/.ssh/idss_broker_deploy -o StrictHostKeyChecking=accept-new \
            deploy@100.98.48.68 sudo /usr/local/sbin/idss-broker-install ${{ steps.sha.outputs.sha }}

The docs-only guard (the "Skip if not published" step) is the one nuance to get
right: workflow_run fires for every ci run, but publish-broker skips
non-broker pushes, so the deploy must no-op when the sha has no package rather
than red on a missing download.

Acceptance (from #688)

  • Pushing a broker/** change to main produces a registry package for that sha
    (CI green).
  • workflow_dispatch of broker-deploy with that sha (once the droplet half —
    the ready-for-human sibling of this issue — is in place) ends with
    broker booted … version=… in the journal and offer answering.

Non-goals

Same as #688: no blue/green, no containerising, no env/credential-layout change.
Depends on the droplet one-time setup (its own ready-for-human follow-up) and
the repo secrets REGISTRY_FORGEJO_TOKEN (exists) + BROKER_DEPLOY_SSH_KEY (new).

## Why (protected path — filed from #688 by a Sandcastle worker) #688 asks the broker to ride the ADR 0185 auto-deploy rail. Two of its deliverables live under `.forgejo/workflows/`, which is a **protected path** (rule 9 / #445): a worker that edits it has the change rolled back and the run failed loud. So the worker landed everything else for #688 — the install leg `scripts/broker/idss-broker-install.sh` (offline-tested, `scripts/tests/broker-install-test.sh`), the `broker/README.md` runbook, and the `docs/GOTCHAS.md` #59 entry — and files the `.forgejo/` half here for a session to apply (ADR 0174: a `.forgejo/` machinery change needs an interactive session's standing). The install leg is already merged and proven: a session only needs to add the two workflow pieces below and confirm one real publish+deploy. ## Deliverable 1 — CI publishes the broker Add a `publish-broker` job to `.forgejo/workflows/ci.yml`, mirroring the existing `publish` (agent) job: on a push to `main` whose range touched `broker/**` (or `go.mod`/`go.sum`), build `ourcloud-broker` and PUT it to the Forgejo generic registry as `idss-broker/<fullsha>/ourcloud-broker-x86_64` (+ `.sha256` + a `RELEASE` file), idempotent on 409. Uses `secrets.REGISTRY_FORGEJO_TOKEN` (the swarm token has no `write:package` scope — see the `publish` job's comment). Proposed job (starting point — match the `publish` job's PATH/nix idiom): ```yaml publish-broker: needs: seam if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: matou-workstation timeout-minutes: 20 steps: - uses: actions/checkout@v4 with: { fetch-depth: 0 } - name: Publish broker binary if broker/** changed env: FORGEJO_TOKEN: ${{ secrets.REGISTRY_FORGEJO_TOKEN }} FORGEJO_SERVER: ${{ github.server_url }} GIT_SHA: ${{ github.sha }} GIT_BASE: ${{ github.event.before }} run: | set -euo pipefail export PATH="/nix/var/nix/profiles/default/bin:$PATH" base="${GIT_BASE:-HEAD^}"; sha="${GIT_SHA:-HEAD}"; full="$(git rev-parse "$sha")" if ! git diff --name-only "$base" "$full" | grep -Eq '^(broker/|go\.mod|go\.sum)'; then echo "publish-broker: no broker-affecting change in ${base}..${full:0:12} — nothing to publish"; exit 0 fi server="${FORGEJO_SERVER:-https://git.matou.nz}"; owner=Matou; package=idss-broker work="$(mktemp -d)"; trap 'rm -rf "$work"' EXIT; bin="$work/ourcloud-broker-x86_64" nix develop --extra-experimental-features 'nix-command flakes' --command bash -c \ "cd broker && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -o '$bin' ./cmd/broker" sum="$(cd "$work" && sha256sum ourcloud-broker-x86_64 | awk '{print $1}')" printf '%s ourcloud-broker-x86_64\n' "$sum" > "$work/ourcloud-broker-x86_64.sha256" printf '%s\n' "$full" > "$work/RELEASE" put() { local c; c="$(curl -sS -o /dev/null -w '%{http_code}' -H "Authorization: token $FORGEJO_TOKEN" --upload-file "$1" "$server/api/packages/$owner/generic/$package/$full/$2")" case "$c" in 200|201|204) echo "uploaded $2 ($c)";; 409) echo "$2 already present ($c)";; *) echo "FAILED $2 -> $c" >&2; return 1;; esac; } put "$bin" ourcloud-broker-x86_64 put "$work/ourcloud-broker-x86_64.sha256" ourcloud-broker-x86_64.sha256 put "$work/RELEASE" RELEASE echo "publish-broker: idss-broker@${full:0:12} published (sha256 $sum)" ``` ## Deliverable 3 — the deploy workflow Add `.forgejo/workflows/broker-deploy.yml` on the `matou-workstation` runner (on the Netbird mesh): `workflow_dispatch` with a `sha` input, and an automatic run after CI's publish job on `main` — `ssh deploy@100.98.48.68 sudo /usr/local/sbin/idss-broker-install <sha>`, key = `secrets.BROKER_DEPLOY_SSH_KEY` (a NEW `deploy` user's key, NOT `dev`). Starting point: ```yaml name: broker-deploy on: workflow_dispatch: inputs: sha: { description: full git sha CI published the broker under, required: true } workflow_run: workflows: [ci] types: [completed] branches: [main] jobs: deploy: runs-on: matou-workstation timeout-minutes: 15 if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' steps: - name: Resolve sha id: sha run: | if [ "${{ github.event_name }}" = workflow_dispatch ]; then s="${{ github.event.inputs.sha }}"; else s="${{ github.event.workflow_run.head_sha }}"; fi echo "sha=$s" >> "$GITHUB_OUTPUT" - name: Skip if this sha was not published (docs-only push, etc.) id: pub run: | code="$(curl -sS -o /dev/null -w '%{http_code}' \ https://git.matou.nz/api/packages/Matou/generic/idss-broker/${{ steps.sha.outputs.sha }}/ourcloud-broker-x86_64)" if [ "$code" = 200 ]; then echo "go=1" >> "$GITHUB_OUTPUT"; else echo "publish-broker skipped this sha ($code) — nothing to deploy"; echo "go=0" >> "$GITHUB_OUTPUT"; fi - name: Deploy if: steps.pub.outputs.go == '1' run: | install -d -m700 ~/.ssh printf '%s\n' "${{ secrets.BROKER_DEPLOY_SSH_KEY }}" > ~/.ssh/idss_broker_deploy chmod 600 ~/.ssh/idss_broker_deploy ssh -i ~/.ssh/idss_broker_deploy -o StrictHostKeyChecking=accept-new \ deploy@100.98.48.68 sudo /usr/local/sbin/idss-broker-install ${{ steps.sha.outputs.sha }} ``` The docs-only guard (the "Skip if not published" step) is the one nuance to get right: `workflow_run` fires for every `ci` run, but `publish-broker` skips non-broker pushes, so the deploy must no-op when the sha has no package rather than red on a missing download. ## Acceptance (from #688) - Pushing a `broker/**` change to `main` produces a registry package for that sha (CI green). - `workflow_dispatch` of `broker-deploy` with that sha (once the droplet half — the `ready-for-human` sibling of this issue — is in place) ends with `broker booted … version=…` in the journal and `offer` answering. ## Non-goals Same as #688: no blue/green, no containerising, no env/credential-layout change. Depends on the droplet one-time setup (its own `ready-for-human` follow-up) and the repo secrets `REGISTRY_FORGEJO_TOKEN` (exists) + `BROKER_DEPLOY_SSH_KEY` (new).
Author
Member

Close report

Landed the .forgejo/ half of #688's auto-deploy rail (this ticket's whole scope):

  • publish-broker job added to .forgejo/workflows/ci.yml (164027d8) — mirrors the existing publish job: on a push to main touching broker/**/go.mod/go.sum, builds ourcloud-broker and PUTs it to the Forgejo generic registry as idss-broker/<fullsha>/ourcloud-broker-x86_64 (+ .sha256 + RELEASE), idempotent on 409, no-op on an unrelated push.
  • .forgejo/workflows/broker-deploy.yml added (164027d8) — workflow_dispatch (sha input) or automatic workflow_run after ci on main, with a skip-if-not-published guard, then ssh deploy@100.98.48.68 sudo /usr/local/sbin/idss-broker-install <sha>.

Both were a session's-standing edit — .forgejo/workflows/ is a protected path a worker cannot touch (#445) — landed directly, no ADR 0174 judgement call involved (the YAML was fully specified by this ticket).

Live proof (acceptance criterion 1 — CI green, real registry package)

Pushed 0763e143 (a genuine broker/README.md change) to main:

  • seam → green, publish-broker → green (run 9136, job 18156).
  • Registry package minted for real: GET .../packages/Matou/generic/idss-broker/0763e143dba1b362bdc44bfc5aa8f0c8a66b1841/{ourcloud-broker-x86_64,ourcloud-broker-x86_64.sha256,RELEASE} → all 200, RELEASE correctly names 0763e143dba1b362bdc44bfc5aa8f0c8a66b1841.
  • Guard proven the other direction too: dispatching ci.yml manually (no broker change in the dispatch's own diff window) leaves both publish/publish-broker skipped — never fires off-push, matching the existing publish job's own discipline.

broker-deploy.yml — dispatched against the same sha

Resolved the sha and correctly detected the package as published (go=1), then failed at the ssh step — expected: #690 (droplet one-time setup: deploy user, sudoers line, BROKER_DEPLOY_SSH_KEY secret) is still ready-for-human and open, so the secret doesn't exist yet. No risk to the live broker — nothing on the droplet trusts this key until #690 lands, and the installer's own rollback discipline (#688) covers the day it does.

What's left

Full end-to-end proof (workflow_dispatch of broker-deploy ending in broker booted … version=… + a 200 from /v1/gateways/offer) is gated on #690 alone now — this ticket's own acceptance criteria already scoped it that way. Nothing further for a session to do here.

STATUS.md updated in 164027d8/a91b3b7f. broker/README.md's "Deploy" section updated to match.

Ruled by agent under ADR 0174 (rule 5, ready-for-session — protected-path edit, no judgement call) — veto anytime.

## Close report Landed the `.forgejo/` half of #688's auto-deploy rail (this ticket's whole scope): - **`publish-broker`** job added to `.forgejo/workflows/ci.yml` (`164027d8`) — mirrors the existing `publish` job: on a push to `main` touching `broker/**`/`go.mod`/`go.sum`, builds `ourcloud-broker` and PUTs it to the Forgejo generic registry as `idss-broker/<fullsha>/ourcloud-broker-x86_64` (+ `.sha256` + `RELEASE`), idempotent on 409, no-op on an unrelated push. - **`.forgejo/workflows/broker-deploy.yml`** added (`164027d8`) — `workflow_dispatch` (`sha` input) or automatic `workflow_run` after `ci` on `main`, with a skip-if-not-published guard, then `ssh deploy@100.98.48.68 sudo /usr/local/sbin/idss-broker-install <sha>`. Both were a session's-standing edit — `.forgejo/workflows/` is a protected path a worker cannot touch (#445) — landed directly, no ADR 0174 judgement call involved (the YAML was fully specified by this ticket). ### Live proof (acceptance criterion 1 — CI green, real registry package) Pushed `0763e143` (a genuine `broker/README.md` change) to `main`: - `seam` → green, `publish-broker` → green (run 9136, job 18156). - Registry package minted for real: `GET .../packages/Matou/generic/idss-broker/0763e143dba1b362bdc44bfc5aa8f0c8a66b1841/{ourcloud-broker-x86_64,ourcloud-broker-x86_64.sha256,RELEASE}` → all `200`, `RELEASE` correctly names `0763e143dba1b362bdc44bfc5aa8f0c8a66b1841`. - Guard proven the other direction too: dispatching `ci.yml` manually (no broker change in the dispatch's own diff window) leaves both `publish`/`publish-broker` `skipped` — never fires off-push, matching the existing `publish` job's own discipline. ### broker-deploy.yml — dispatched against the same sha Resolved the sha and correctly detected the package as published (`go=1`), then failed at the `ssh` step — **expected**: #690 (droplet one-time setup: `deploy` user, sudoers line, `BROKER_DEPLOY_SSH_KEY` secret) is still `ready-for-human` and open, so the secret doesn't exist yet. No risk to the live broker — nothing on the droplet trusts this key until #690 lands, and the installer's own rollback discipline (#688) covers the day it does. ### What's left Full end-to-end proof (`workflow_dispatch` of `broker-deploy` ending in `broker booted … version=…` + a 200 from `/v1/gateways/offer`) is gated on #690 alone now — this ticket's own acceptance criteria already scoped it that way. Nothing further for a session to do here. `STATUS.md` updated in `164027d8`/`a91b3b7f`. `broker/README.md`'s "Deploy" section updated to match. Ruled by agent under ADR 0174 (rule 5, `ready-for-session` — protected-path edit, no judgement call) — veto anytime.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#689
No description provided.