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
+67
-2
@@ -226,10 +226,75 @@ jobs:
|
||||
-d "{\"tag_name\":\"${TAG}\",\"target\":\"${{ github.sha }}\",\"message\":\"Deployed to production\"}" \
|
||||
"https://code.lotusguild.org/api/v1/repos/${{ github.repository }}/tags"
|
||||
|
||||
deploy-worker:
|
||||
name: Deploy worker
|
||||
runs-on: ubuntu-latest
|
||||
container: node:20-bookworm
|
||||
needs: [deploy] # the server first: it must understand anything new the worker sends
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
concurrency:
|
||||
group: deploy-worker
|
||||
cancel-in-progress: false
|
||||
steps:
|
||||
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
||||
with:
|
||||
fetch-depth: 0 # to compare against the commit the worker runs now
|
||||
- name: Did the worker change since the running version?
|
||||
id: changed
|
||||
env:
|
||||
GIT_SHA: ${{ github.sha }}
|
||||
run: |
|
||||
# Restarting the worker briefly interrupts Gandalf's commands, so only
|
||||
# deploy when worker code or its dependencies changed (#40).
|
||||
running=$(curl -fsS --max-time 5 http://10.10.10.65:8080/healthz \
|
||||
| node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>console.log((JSON.parse(s).worker_versions||[]).join(" ")))')
|
||||
echo "Workers run: ${running:-none}"
|
||||
deploy=false
|
||||
[ -n "$running" ] || deploy=true
|
||||
for v in $running; do
|
||||
if ! git cat-file -e "${v}^{commit}" 2>/dev/null \
|
||||
|| ! git diff --quiet "$v" "$GIT_SHA" -- worker/ package.json package-lock.json; then
|
||||
deploy=true
|
||||
fi
|
||||
done
|
||||
echo "deploy=$deploy" >> "$GITHUB_OUTPUT"
|
||||
echo "Deploy the worker: $deploy"
|
||||
- name: Trigger worker webhook
|
||||
if: steps.changed.outputs.deploy == 'true'
|
||||
env:
|
||||
WEBHOOK_SECRET: ${{ secrets.WORKER_WEBHOOK_SECRET }}
|
||||
GIT_REF: ${{ github.ref }}
|
||||
GIT_SHA: ${{ github.sha }}
|
||||
run: |
|
||||
PAYLOAD="{\"ref\":\"${GIT_REF}\",\"sha\":\"${GIT_SHA}\",\"ts\":$(date +%s)}"
|
||||
SIG=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | awk '{print $2}')
|
||||
curl -sf --connect-timeout 10 -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-Gitea-Signature: ${SIG}" \
|
||||
-d "$PAYLOAD" \
|
||||
"http://10.10.10.151:9000/hooks/pulse-worker-deploy"
|
||||
- name: Verify the worker reconnected on this commit
|
||||
if: steps.changed.outputs.deploy == 'true'
|
||||
env:
|
||||
GIT_SHA: ${{ github.sha }}
|
||||
run: |
|
||||
# deploy/pulse_worker_deploy.sh on CT 153 installs this sha, restarts the
|
||||
# worker, and restores the previous files if it never reconnects.
|
||||
for _ 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 -Eq "\"worker_versions\":\[[^]]*\"${GIT_SHA}\""; then
|
||||
echo "Worker connected on ${GIT_SHA}: ${body}"
|
||||
exit 0
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
echo "::error::The worker never reconnected on ${GIT_SHA} (last /healthz: ${body:-no response}). See /var/log/pulse-worker-deploy.log on CT 153."
|
||||
exit 1
|
||||
|
||||
notify:
|
||||
name: Notify
|
||||
runs-on: ubuntu-latest
|
||||
needs: [lint, test, audit, scan, integration, ui, deploy]
|
||||
needs: [lint, test, audit, scan, integration, ui, deploy, deploy-worker]
|
||||
# Alert on any failure on main or in the weekly audit, and on every deploy outcome.
|
||||
if: >-
|
||||
always() && (
|
||||
@@ -243,7 +308,7 @@ jobs:
|
||||
REPO: ${{ github.repository }}
|
||||
BRANCH: ${{ github.ref_name }}
|
||||
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
RESULTS: "lint=${{ needs.lint.result }} test=${{ needs.test.result }} audit=${{ needs.audit.result }} scan=${{ needs.scan.result }} integration=${{ needs.integration.result }} ui=${{ needs.ui.result }} deploy=${{ needs.deploy.result }}"
|
||||
RESULTS: "lint=${{ needs.lint.result }} test=${{ needs.test.result }} audit=${{ needs.audit.result }} scan=${{ needs.scan.result }} integration=${{ needs.integration.result }} ui=${{ needs.ui.result }} deploy=${{ needs.deploy.result }} worker=${{ needs.deploy-worker.result }}"
|
||||
DEPLOYED: ${{ needs.deploy.result == 'success' }}
|
||||
run: |
|
||||
if [ -z "$MATRIX_WEBHOOK_URL" ] || [ "$MATRIX_WEBHOOK_URL" = "CONFIGURE_ME" ]; then exit 0; fi
|
||||
|
||||
Reference in new issue
Block a user