CI: one pipeline that gates the deploy on every check and waits for prod to run it (#55, part 1) #76

Merged
jared merged 4 commits from ci-deploy-gate into main 2026-11-29 00:00:28 -05:00
Owner

Part 1 of #55. Nothing changes on the server: today's webhook and deploy script keep working with the new payload.

The problems in #55, and what this does

#55 Now
1. Deploy only waited for lint; failing tests or a bandit finding still deployed Deploy needs every job: Lint (Python), Lint (JS), Test, Security and Scan
2. The payload was just {"ref"} (replayable forever); nothing checked the deploy Signed payload {"ref","sha","ts"}, unique per request. CI waits up to 5 minutes until /health reports that commit for the web app (sha) and the monitor (monitor_sha) with status ok, and only then tags deploy-<date>-<run>
3. actions/checkout@v3, a moving tag Pinned to a full SHA: 11d5960a... # v4.4.0
4. Unpinned tools, and the test environment might not match production Pinned tools in requirements-dev.txt (flake8 7.5.0, bandit 1.9.4, pytest 9.2.0, pytest-cov 7.1.0). Job images pinned by digest: python:3.13-trixie (CT 157 runs Python 3.13.5 on Debian 13) and node:22-bookworm for eslint via npm ci. No setup-python, which broke Pulse twice through the runner's shared tool cache
5. Only lint failures alerted Notify: any failure on main or in the weekly run, and every deploy
new Scan job: gitleaks over the full history (it would have caught the config backup removed in #74), actionlint with shellcheck on the workflow, and shellcheck on *.sh. Downloads are pinned and SHA-256 checked

Other changes:

  • One file: ci.yml replaces lint.yml, test.yml and security.yml.
  • When it runs: on pull requests, on pushes to main, and Mondays at 06:00 UTC. Branch pushes no longer build twice. Deploys queue and are never cancelled mid-way.
  • version.py: reads the checked-out commit from .git at startup, with no subprocess. It handles a detached HEAD, loose refs and packed-refs, and gives '' if anything is unreadable.

Checked before opening

  • Local runs: I ran every job's commands with the pinned versions in a fresh virtualenv:
    • flake8 is clean;
    • bandit -ll is clean (the same informational warnings as today);
    • 765 tests pass at 76% coverage;
    • the deploy job's inline Python compiles.
  • Scanners: actionlint 1.7.12 (with shellcheck) is clean on ci.yml. gitleaks 8.30.1 over the full, purged history scanned 264 commits and found nothing.
  • Prod's /health is reachable through nginx from the LAN at http://10.10.10.61/health, which is what the verify step polls.

Branch protection (done 2026-11-29)

main now requires the new checks:

CI / Lint (Python) (pull_request)
CI / Lint (JS) (pull_request)
CI / Test (pull_request)
CI / Security (pull_request)
CI / Scan (pull_request)

They replace Lint / Python (flake8) (push), Lint / JS (eslint) (push), Security / Python Security (bandit) (push) and Test / Python Tests (pytest) (push). Those came from the workflows this PR removes, so they would never report again.

Part 2 (#77, server side, needs approval)

  • deploy/gandalf_deploy.sh in this repo: it refuses requests older than 5 minutes or not newer than the last one, checks that the sha is on origin/main, checks it out detached, installs, restarts, waits for /health to report it, and rolls back if it never does.
  • The webhook passes sha and ts to it.
  • The pve-infra 157-gandalf/deploy.sh keeps only the config files, so a pve-infra push no longer redeploys whatever main happens to be.

🤖 Generated with Claude Code

Part 1 of #55. Nothing changes on the server: today's webhook and deploy script keep working with the new payload. ## The problems in #55, and what this does | #55 | Now | |---|---| | 1. Deploy only waited for lint; failing tests or a bandit finding still deployed | **Deploy needs every job:** Lint (Python), Lint (JS), Test, Security and Scan | | 2. The payload was just `{"ref"}` (replayable forever); nothing checked the deploy | **Signed payload** `{"ref","sha","ts"}`, unique per request. **CI waits up to 5 minutes** until `/health` reports that commit for the web app (`sha`) and the monitor (`monitor_sha`) with status ok, and only then tags `deploy-<date>-<run>` | | 3. `actions/checkout@v3`, a moving tag | **Pinned to a full SHA**: `11d5960a... # v4.4.0` | | 4. Unpinned tools, and the test environment might not match production | **Pinned tools** in `requirements-dev.txt` (flake8 7.5.0, bandit 1.9.4, pytest 9.2.0, pytest-cov 7.1.0). **Job images pinned by digest:** `python:3.13-trixie` (CT 157 runs Python 3.13.5 on Debian 13) and `node:22-bookworm` for eslint via `npm ci`. No setup-python, which broke Pulse twice through the runner's shared tool cache | | 5. Only lint failures alerted | **Notify:** any failure on `main` or in the weekly run, and every deploy | | new | **Scan job:** gitleaks over the full history (it would have caught the config backup removed in #74), actionlint with shellcheck on the workflow, and shellcheck on `*.sh`. Downloads are pinned and SHA-256 checked | Other changes: - **One file:** `ci.yml` replaces `lint.yml`, `test.yml` and `security.yml`. - **When it runs:** on pull requests, on pushes to `main`, and Mondays at 06:00 UTC. Branch pushes no longer build twice. Deploys queue and are never cancelled mid-way. - **`version.py`:** reads the checked-out commit from `.git` at startup, with no subprocess. It handles a detached HEAD, loose refs and packed-refs, and gives `''` if anything is unreadable. ## Checked before opening - **Local runs:** I ran every job's commands with the pinned versions in a fresh virtualenv: - flake8 is clean; - bandit `-ll` is clean (the same informational warnings as today); - 765 tests pass at 76% coverage; - the deploy job's inline Python compiles. - **Scanners:** actionlint 1.7.12 (with shellcheck) is clean on `ci.yml`. gitleaks 8.30.1 over the full, purged history scanned 264 commits and found nothing. - **Prod's `/health`** is reachable through nginx from the LAN at `http://10.10.10.61/health`, which is what the verify step polls. ## Branch protection (done 2026-11-29) `main` now requires the new checks: ``` CI / Lint (Python) (pull_request) CI / Lint (JS) (pull_request) CI / Test (pull_request) CI / Security (pull_request) CI / Scan (pull_request) ``` They replace `Lint / Python (flake8) (push)`, `Lint / JS (eslint) (push)`, `Security / Python Security (bandit) (push)` and `Test / Python Tests (pytest) (push)`. Those came from the workflows this PR removes, so they would never report again. ## Part 2 (#77, server side, needs approval) - `deploy/gandalf_deploy.sh` in this repo: it refuses requests older than 5 minutes or not newer than the last one, checks that the sha is on `origin/main`, checks it out detached, installs, restarts, waits for `/health` to report it, and rolls back if it never does. - The webhook passes `sha` and `ts` to it. - The pve-infra `157-gandalf/deploy.sh` keeps only the config files, so a pve-infra push no longer redeploys whatever `main` happens to be. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 2 commits 2026-11-28 23:43:44 -05:00
gandalf#55, part 1 (no server changes needed).

- .gitea/workflows/ci.yml replaces lint.yml, test.yml and security.yml.
  Jobs: Lint (Python) with the dash check, Lint (JS), Test, Security,
  Scan (gitleaks over the full history, actionlint, shellcheck), Deploy
  and Notify. Deploy needs every check, so failing tests or a bandit or
  gitleaks finding no longer reach production.
- Pinned: actions/checkout to a full SHA, job images to digests (Python
  3.13 on Debian 13 like CT 157, Node 22 for eslint), Python tools in the
  new requirements-dev.txt, scanner downloads by SHA-256. No setup-python
  (the runner's shared tool cache broke Pulse twice).
- Builds run on pull requests and on pushes to main only, plus a weekly
  run on main; concurrency queues deploys and never cancels one.
- Deploy signs {"ref", "sha", "ts"} (unique per request), then waits up to
  5 minutes until /health reports that commit for both processes, and only
  then tags deploy-<date>-<run>.
- /health reports `sha` (version.py reads .git at startup, no subprocess)
  and `monitor_sha` (the monitor writes it every cycle).

Part 2 (server side): the pinned deploy script that refuses stale or
replayed requests, deploys exactly that sha and rolls back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gitignore: keep node_modules/ and .coverage on separate lines
CI / Lint (Python) (pull_request) Failing after 16s
CI / Lint (JS) (pull_request) Successful in 1m7s
CI / Test (pull_request) Failing after 10s
CI / Security (pull_request) Failing after 9s
CI / Scan (pull_request) Failing after 7s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
58e4528eb5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
jared added 1 commit 2026-11-28 23:52:25 -05:00
CI: install Node before checkout in the Python jobs
CI / Lint (JS) (pull_request) Successful in 10s
CI / Lint (Python) (pull_request) Failing after 36s
CI / Test (pull_request) Successful in 56s
CI / Security (pull_request) Successful in 32s
CI / Scan (pull_request) Successful in 28s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
77a5791bbf
The runner (act) runs JavaScript actions such as actions/checkout inside
the job container, and python:3.13-trixie has no node, so checkout failed
with 'exec: node: executable file not found'. Debian's nodejs (20.x) is
enough for checkout v4 and keeps the job image matching production.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jared added 1 commit 2026-11-28 23:54:43 -05:00
monitor: space after a comma in an f-string (flake8 E231 on Python 3.13)
CI / Lint (Python) (pull_request) Successful in 36s
CI / Lint (JS) (pull_request) Successful in 16s
CI / Security (pull_request) Successful in 44s
CI / Test (pull_request) Successful in 54s
CI / Scan (pull_request) Successful in 48s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
8a23fe0922
Python 3.12+ tokenizes f-strings, so pycodestyle now checks inside them.
CI runs flake8 on production's Python 3.13; the old CI and local checks
ran an older Python and never saw it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jared merged commit b71d5f4c24 into main 2026-11-29 00:00:28 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/gandalf#76