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

#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:
jaredandClaude Opus 5.5 committed 2026-11-22 02:25:35 -05:00
1 parent b10ea154dd
commit cb12fec28c
5 files changed
+311 -17

No files matched your search

+14 -9
View File
@@ -98,18 +98,23 @@ jobs:
-d "$PAYLOAD" \
"http://10.10.10.65:9000/hooks/pulse-deploy"
- name: Wait for Pulse to come back
- name: Verify production runs this commit
env:
GIT_SHA: ${{ github.sha }}
run: |
# Liveness only: the webhook returns before the restart finishes, so this
# can't prove the new commit is running. /healthz with the git SHA
# replaces it in #45 phase 2. The unauthenticated root answers 401 when up.
sleep 30
for i in $(seq 1 24); do
code=$(curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://10.10.10.65:8080/ || true)
if [ "$code" = "401" ]; then echo "Pulse is serving (HTTP $code)"; exit 0; fi
# The webhook returns at once; the server-side deploy script checks out
# this exact sha, runs npm ci and restarts, and rolls back if /healthz
# never reports it. Succeed only when production reports this sha with
# a working database (up to 4 minutes, covering npm ci).
for i in $(seq 1 48); do
body=$(curl -fsS --connect-timeout 5 --max-time 5 http://10.10.10.65:8080/healthz || true)
if echo "$body" | grep -q "\"sha\":\"${GIT_SHA}\"" && echo "$body" | grep -q '"db":true'; then
echo "Production is healthy on ${GIT_SHA}: ${body}"
exit 0
fi
sleep 5
done
echo "::error::Pulse did not come back within 2 minutes after deploy"
echo "::error::Production never reported ${GIT_SHA} as healthy (last /healthz: ${body:-no response}). The server rolls back automatically; see /var/log/pulse-deploy.log on CT 122."
exit 1
- name: Tag deployed commit