Worker deploys from CI, with version reporting (#40)
CI / Lint (eslint) (push) Successful in 14s
CI / Test (jest) (push) Successful in 18s
CI / Security (npm audit) (push) Successful in 12s
CI / Integration (api) (push) Successful in 1m14s
CI / Scan (secrets, workflows, shell) (push) Successful in 1m29s
CI / Lint (eslint) (pull_request) Successful in 19s
CI / Test (jest) (pull_request) Successful in 13s
CI / Security (npm audit) (pull_request) Successful in 7s
CI / UI (playwright) (push) Successful in 1m43s
CI / Deploy (push) Skipped
CI / Deploy worker (push) Skipped
CI / Notify (push) Skipped
CI / Integration (api) (pull_request) Successful in 1m51s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 2m20s
CI / UI (playwright) (pull_request) Successful in 1m37s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / Lint (eslint) (push) Successful in 14s
CI / Test (jest) (push) Successful in 18s
CI / Security (npm audit) (push) Successful in 12s
CI / Integration (api) (push) Successful in 1m14s
CI / Scan (secrets, workflows, shell) (push) Successful in 1m29s
CI / Lint (eslint) (pull_request) Successful in 19s
CI / Test (jest) (pull_request) Successful in 13s
CI / Security (npm audit) (pull_request) Successful in 7s
CI / UI (playwright) (push) Successful in 1m43s
CI / Deploy (push) Skipped
CI / Deploy worker (push) Skipped
CI / Notify (push) Skipped
CI / Integration (api) (pull_request) Successful in 1m51s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 2m20s
CI / UI (playwright) (pull_request) Successful in 1m37s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
- The worker reports its commit (VERSION file, or git rev-parse in a checkout) in worker_connect and heartbeat metadata. The server keeps it per live socket and /healthz lists worker_versions. - deploy/pulse_worker_deploy.sh <sha> <ts>, for the webhook on a worker host: replay and age checks, commit must be on main, installs worker.js and the npm manifests from exactly that commit, writes VERSION, npm ci, restarts, waits until /healthz lists the sha, else restores the previous files. Sandbox tests cover deploy, replay, stale and malformed input, off-main commits, no-op redeploys and rollback. - New CI job Deploy worker after Deploy: only when worker/ or the npm manifests changed since the commit the workers report, so unrelated merges don't restart the worker; then waits for the worker to reconnect on the new commit. - README: Worker deploys (install, hook definition, adding a worker host). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4f6672a7ef
commit
ea939d4430
9 files changed
+439
-10
No files matched your search
@@ -645,7 +645,8 @@ CI sends an HMAC-signed payload `{"ref", "sha", "ts"}` to the webhook on CT 122.
|
||||
**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.
|
||||
`{status, version, sha, db, workers, worker_versions, uptime_s}` with 200, or 503 when the database is
|
||||
unreachable. `worker_versions` lists the commit each connected worker reports.
|
||||
|
||||
**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:
|
||||
@@ -663,6 +664,55 @@ The `pulse-deploy` hook in `/etc/webhook/hooks.json` passes the signed values as
|
||||
]
|
||||
```
|
||||
|
||||
### Worker deploys
|
||||
|
||||
The only worker today is `pulse-worker-01` (LXC CT 153 on monitor-01, 10.10.10.151), installed in
|
||||
`/opt/pulse-worker` (`worker.js`, the npm manifests, `node_modules`, and its own `.env`), run by
|
||||
`pulse-worker.service`. The unit file itself is deployed from `jared/pve-infra`.
|
||||
|
||||
After the server deploys, the `Deploy worker` job checks the commit the connected workers report
|
||||
(`worker_versions` in `/healthz`). Only if `worker/` or the npm manifests changed since then does it
|
||||
call the HMAC-signed `pulse-worker-deploy` hook on CT 153, so unrelated merges don't restart the
|
||||
worker mid-command. The hook runs `deploy/pulse_worker_deploy.sh <sha> <ts>`, which:
|
||||
|
||||
1. refuses stale or replayed requests, and commits that aren't on `main`;
|
||||
2. reads `worker/worker.js`, `package.json` and `package-lock.json` at exactly that commit from a
|
||||
local clone of the repo, installs them, writes the sha to `VERSION`, runs `npm ci --omit=dev` and
|
||||
restarts the worker (`.env` is never touched);
|
||||
3. waits until `/healthz` lists that sha among the connected workers, and otherwise **restores** the
|
||||
previous files.
|
||||
|
||||
CI then waits for the same thing before the job passes. The script logs to
|
||||
`/var/log/pulse-worker-deploy.log`.
|
||||
|
||||
**Installing it on a worker host** (as root; CT 153 already runs `webhook`):
|
||||
|
||||
```bash
|
||||
install -m 755 pulse_worker_deploy.sh /usr/local/bin/pulse_worker_deploy.sh # from deploy/ in this repo
|
||||
```
|
||||
|
||||
and add a hook to `/etc/webhook/hooks.json`, with the same secret as the repo's
|
||||
`WORKER_WEBHOOK_SECRET` Actions secret:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "pulse-worker-deploy",
|
||||
"execute-command": "/usr/local/bin/pulse_worker_deploy.sh",
|
||||
"pass-arguments-to-command": [
|
||||
{ "source": "payload", "name": "sha" },
|
||||
{ "source": "payload", "name": "ts" }
|
||||
],
|
||||
"trigger-rule": {
|
||||
"match": { "type": "payload-hmac-sha256", "secret": "<WORKER_WEBHOOK_SECRET>",
|
||||
"parameter": { "source": "header", "name": "X-Gitea-Signature" } }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
To add a worker host, install Node 20 and the worker as above, give it a `.env` with `WORKER_NAME`,
|
||||
`PULSE_SERVER`, `PULSE_WS` and `WORKER_API_KEY`, and add its hook (one hook URL per host in the
|
||||
`Deploy worker` job).
|
||||
|
||||
---
|
||||
|
||||
**PULSE** - Orchestrating your infrastructure, one heartbeat at a time. ⚡
|
||||
|
||||
Reference in new issue
Block a user