g1t/deploy/self-host/status.sh
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1 | #!/usr/bin/env bash |
| 2 | # Starts the status page of a self-hosted g1t (apps/status) in a workerd of | |
| 3 | # its own on :8788, so it stays up when the site does not. Its database | |
| 4 | # lives on its own volume. `wrangler dev` runs no crons, so a loop here | |
| 5 | # asks for a round of checks every minute instead. | |
| 6 | set -euo pipefail | |
| 7 | ||
| 8 | cd "$(dirname "$0")" | |
| 9 | DATA="${G1T_DATA:-/data}" | |
| 10 | STATE="$DATA/state" | |
| 11 | GENERATED="$DATA/generated" | |
| 12 | WRANGLER="$(cd ../.. && pwd)/node_modules/.bin/wrangler" | |
| 13 | mkdir -p "$STATE" | |
| 14 | ||
| 15 | # configs.mjs writes every config; only the status page's is used here. | |
| 16 | # It needs nothing secret, so placeholders stand in for the site's keys. | |
| 17 | GITSTORE_SECRET="${GITSTORE_SECRET:-unused}" node configs.mjs "$GENERATED" >/dev/null | |
| 18 | cd "$GENERATED" | |
| 19 | ||
| 20 | echo "Migrating g1t-status" | |
| 21 | "$WRANGLER" d1 migrations apply g1t-status --local --persist-to "$STATE" -c g1t-status.json >/dev/null | |
| 22 | ||
| 23 | # Every minute, the cron's work: check each part and keep the result. | |
| 24 | # (The image has Node but no curl.) | |
| 25 | node -e ' | |
| 26 | const tick = () => fetch("http://127.0.0.1:8788/__scheduled?cron=*+*+*+*+*").catch(() => {}); | |
| 27 | setTimeout(() => { tick(); setInterval(tick, 60_000); }, 15_000); | |
| 28 | ' & | |
| 29 | ||
| 30 | echo "The status page is starting on http://localhost:${STATUS_PORT:-8788}" | |
| 31 | exec "$WRANGLER" dev -c g1t-status.json \ | |
| 32 | --ip 0.0.0.0 --port 8788 \ | |
| 33 | --persist-to "$STATE" \ | |
| 34 | --test-scheduled \ | |
| 35 | --show-interactive-dev-session=false |