CI modelled on Pulse, deploy script with rollback, bootstrap, README
- .gitea/workflows/ci.yml: flake8 + dash check, pytest (90% coverage floor), MariaDB integration tests, bandit, pip-audit, gitleaks, actionlint, shellcheck, zizmor, semgrep; main deploys through a signed webhook and waits for /health to report the commit. - deploy/thor_deploy.sh: deploys an exact sha, installs units and nginx site when changed, rolls back unless /health reports the sha with a working database. Sandbox-tested. - deploy/bootstrap.sh: idempotent first install on CT 173. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eecb24297a
commit
379570bbdc
14 files changed
+689
No files matched your search
@@ -39,3 +39,38 @@ A monitor that runs on a failing host is least reliable exactly when it's needed
|
||||
- hwmonDaemon#39: interim OOM check, which moves here later.
|
||||
- hwmonDaemon#40: the boundary, and which checks move here.
|
||||
- gandalf#57: Gandalf stops calling non-network faults "network".
|
||||
|
||||
## Code layout
|
||||
- `thor/config.py`: settings from `/etc/thor/thor.json` (non-secret) and `/etc/thor/*.env` (secrets).
|
||||
- `thor/clients/`: read-only clients for Prometheus, Loki, Proxmox and Gandalf, and the Tinker ticket client. A source that can't answer raises `SourceError`, which means "unknown", never "nothing found".
|
||||
- `thor/db.py`: MariaDB (CT 149, schema `thor`), versioned migrations, and the queries.
|
||||
- `thor/monitor.py`: the 120 s loop (`thor-monitor.service`): review window since the last good cycle with 24 h catch-up, blind periods per source, writes buffered while the database is away.
|
||||
- `thor/web/`: `thor.service`: `/health` (database + monitor freshness + deployed commit) and `/metrics`.
|
||||
|
||||
The decisions behind all of this are in the plan on thor#1.
|
||||
|
||||
## Development
|
||||
```bash
|
||||
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt -r requirements-dev.txt
|
||||
.venv/bin/python -m pytest # unit tests
|
||||
.venv/bin/flake8 . && .venv/bin/bandit -q -r thor -ll
|
||||
# Database tests need a throwaway MariaDB:
|
||||
THOR_TEST_DB_HOST=127.0.0.1 THOR_TEST_DB_PASSWORD=... .venv/bin/python -m pytest tests/test_db_mariadb.py
|
||||
```
|
||||
CI (`.gitea/workflows/ci.yml`, modelled on Pulse's) runs lint, the dash check, tests with coverage, the MariaDB tests, bandit, pip-audit, gitleaks, actionlint, shellcheck, zizmor and semgrep on every pull request, and deploys `main`.
|
||||
|
||||
## Deploy
|
||||
Thor runs on **CT 173** (`thor`, 10.10.10.86, DHCP reservation), in the HA rule `EMERGENCY needed`.
|
||||
|
||||
| Path | What |
|
||||
|---|---|
|
||||
| `/opt/thor/app` | checkout of this repo (detached at the deployed commit) |
|
||||
| `/opt/thor/venv` | Python virtualenv |
|
||||
| `/opt/thor/revision.env` | `THOR_SHA`, the commit `/health` reports |
|
||||
| `/etc/thor/thor.json` | non-secret settings (`deploy/thor.example.json`) |
|
||||
| `/etc/thor/*.env` | secrets: `pve.env`, `db.env`, `gandalf.env`, `tinker.env` (root:thor 0640, never in git) |
|
||||
| `/etc/webhook/hooks.json` | deploy hook and its HMAC secret (also the repo secret `WEBHOOK_SECRET`) |
|
||||
|
||||
- **First install:** `bash deploy/bootstrap.sh` inside the CT (idempotent).
|
||||
- **Every merge to main:** CI signs `{ref, sha, ts}` and calls the webhook on `:9000`. `/usr/local/bin/thor_deploy.sh` (installed from `deploy/thor_deploy.sh`; reinstall it by hand when it changes) checks out exactly that commit, installs dependencies, units and the nginx site, restarts `thor` and `thor-monitor`, and rolls back unless `/health` reports the commit with a working database. CI then waits for production to report the commit. Log: `/var/log/thor-deploy.log`.
|
||||
- **After a deploy:** prod HEAD, `systemctl is-active thor thor-monitor`, `curl http://10.10.10.86/health`, and no tracebacks in `journalctl -u thor -u thor-monitor`.
|
||||
Reference in new issue
Block a user