flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/deploy/self-host/status.sh

35 lines1,375 bytesCodeBlame
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.
6set -euo pipefail
7
8cd "$(dirname "$0")"
9DATA="${G1T_DATA:-/data}"
10STATE="$DATA/state"
11GENERATED="$DATA/generated"
12WRANGLER="$(cd ../.. && pwd)/node_modules/.bin/wrangler"
13mkdir -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.
17GITSTORE_SECRET="${GITSTORE_SECRET:-unused}" node configs.mjs "$GENERATED" >/dev/null
18cd "$GENERATED"
19
20echo "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.)
25node -e '
26const tick = () => fetch("http://127.0.0.1:8788/__scheduled?cron=*+*+*+*+*").catch(() => {});
27setTimeout(() => { tick(); setInterval(tick, 60_000); }, 15_000);
28' &
29
30echo "The status page is starting on http://localhost:${STATUS_PORT:-8788}"
31exec "$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