Deploys: exact sha, replay protection, health check and automatic rollback
CI / Test (jest) (push) Successful in 47s
CI / Lint (eslint) (push) Successful in 52s
CI / Security (npm audit) (push) Successful in 17s
CI / Deploy (push) Skipped
CI / Notify (push) Skipped
CI / Test (jest) (pull_request) Failing after 12s
CI / Lint (eslint) (pull_request) Successful in 14s
CI / Security (npm audit) (pull_request) Successful in 11s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / Test (jest) (push) Successful in 47s
CI / Lint (eslint) (push) Successful in 52s
CI / Security (npm audit) (push) Successful in 17s
CI / Deploy (push) Skipped
CI / Notify (push) Skipped
CI / Test (jest) (pull_request) Failing after 12s
CI / Lint (eslint) (pull_request) Successful in 14s
CI / Security (npm audit) (pull_request) Successful in 11s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
#45 phase 2. - GET /healthz (unauthenticated): running git sha, version, database reachability, connected workers, uptime. 503 when the database is down. - deploy/pulse_deploy.sh, versioned for the first time (it only existed as a hand-edited file on CT 122). It takes <sha> <ts> from the signed webhook payload and: - refuses requests older than 5 minutes, or not newer than the last accepted one (replays); - refuses commits that aren't on main; - checks out exactly that sha (before, it deployed whatever main was); - runs npm ci --omit=dev (before, npm install --production) and restarts; - waits for /healthz to report the sha with a working database, and otherwise rolls back to the previous commit. - tests/deploy-script.test.js runs the script in a sandbox (temporary git origin, fake systemctl/npm/curl): exact-sha deploy with .env kept, replay, stale request, off-main commit, malformed input, and rollback of an unhealthy build. - CI's deploy job now succeeds only once production reports the tested sha as healthy, before tagging. Before, it only checked that the server answered. - README: CI/CD and deploy documentation, including installing the script and the hooks.json arguments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b10ea154dd
commit
cb12fec28c
5 files changed
+311
-17
No files matched your search
@@ -582,17 +582,49 @@ MIT License - See LICENSE file for details
|
||||
|
||||
## CI / CD
|
||||
|
||||
| Workflow | Purpose | Triggers |
|
||||
Everything runs from `.gitea/workflows/ci.yml`:
|
||||
|
||||
| Job | What it does | When |
|
||||
|---|---|---|
|
||||
| `lint.yml` | ESLint on all `.js` files | Every push and PR |
|
||||
| `test.yml` | Jest unit tests (`lib/utils.js`) | Every push and PR |
|
||||
| `security.yml` | `npm audit --audit-level=high` | Every push, PR, and weekly Monday 6am |
|
||||
| `deploy` job in `lint.yml` | Calls the `pulse-deploy` webhook on CT122 (10.10.10.65) to pull + restart | Push to `main` only, after lint passes |
|
||||
| `Lint (eslint)` | `npm run lint`, plus a check that fails on em or en dashes in Pulse-owned files | Every push and PR |
|
||||
| `Test (jest)` | `npm test`: unit tests for `lib/` and the deploy-script sandbox tests | Every push and PR |
|
||||
| `Security (npm audit)` | `npm audit --audit-level=high` | Every push and PR, and weekly (Monday 06:00) |
|
||||
| `Deploy` | Calls the `pulse-deploy` webhook on CT 122, waits until `/healthz` reports the tested commit, then tags it `deploy-*` | Push to `main`, only after all three checks pass |
|
||||
| `Notify` | Matrix alert on any failure on `main` or in the weekly audit, and on every deploy | As needed |
|
||||
|
||||
All CI lives in `.gitea/workflows/ci.yml`. Branch protection on `main` requires its `Lint (eslint)`, `Test (jest)` and `Security (npm audit)` checks, and the `Deploy` job only runs after all three pass on a push to `main`.
|
||||
Branch protection on `main` requires `CI / Lint (eslint) (push)`, `CI / Test (jest) (push)` and
|
||||
`CI / Security (npm audit) (push)`. Actions are pinned to commit SHAs and builds use `npm ci`.
|
||||
The plan for the rest of the pipeline is tracked in #45.
|
||||
|
||||
Tests live in `tests/utils.test.js` and cover the pure utility functions in `lib/utils.js`:
|
||||
`validateWebhookUrl`, `applyParams`, `evalCondition`, `calculateNextRun`.
|
||||
### Deploys
|
||||
|
||||
CI sends an HMAC-signed payload `{"ref", "sha", "ts"}` to the webhook on CT 122. The webhook runs
|
||||
`deploy/pulse_deploy.sh <sha> <ts>`, which:
|
||||
|
||||
1. refuses requests signed more than 5 minutes ago, or not newer than the last accepted one (replays);
|
||||
2. refuses commits that aren't on `main`;
|
||||
3. checks out exactly that commit, runs `npm ci --omit=dev` and restarts `pulse`;
|
||||
4. waits for `GET /healthz` to report that commit with a working database, and otherwise
|
||||
**rolls back** to the previous commit.
|
||||
|
||||
It logs to `/var/log/pulse-deploy.log`. `GET /healthz` (unauthenticated) returns
|
||||
`{status, version, sha, db, workers, uptime_s}` with 200, or 503 when the database is unreachable.
|
||||
|
||||
**Installing or updating the deploy script** (on CT 122, as root). The webhook runs the installed
|
||||
copy, not the one in the checkout, so a bad commit can't replace the code that rolls it back:
|
||||
|
||||
```bash
|
||||
install -m 755 /opt/pulse-server/deploy/pulse_deploy.sh /usr/local/bin/pulse_deploy.sh
|
||||
```
|
||||
|
||||
The `pulse-deploy` hook in `/etc/webhook/hooks.json` passes the signed values as arguments:
|
||||
|
||||
```json
|
||||
"pass-arguments-to-command": [
|
||||
{ "source": "payload", "name": "sha" },
|
||||
{ "source": "payload", "name": "ts" }
|
||||
]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in new issue
Block a user