Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 14s
Release / Gitea release (push) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
4.9 KiB
Bash
Executable File
106 lines
4.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Regenerates the screenshots in docs/img from the real Urutau dashboard.
|
|
#
|
|
# Nothing in the pictures is real: scripts/screenshots/demo writes a DEMO geolocation
|
|
# database (MMDB, city + asn) that maps sub-ranges of the reserved documentation addresses
|
|
# (198.18.0.0/15, 203.0.113.0/24, 198.51.100.0/24, 192.0.2.0/24, 2001:db8::/32) to real
|
|
# cities, plus 30 days of synthetic Traefik / auth.log / fail2ban.log files for two servers
|
|
# (edge-1, edge-2) with domains under example.com/.org/.net. Two Urutau instances (a hub and
|
|
# one peer, ports 18880/18881) read them, new events keep arriving while the pages are
|
|
# captured (so the live map has arcs), and headless Chrome takes the pictures.
|
|
#
|
|
# scripts/screenshots.sh # writes docs/img
|
|
# OUT=/tmp/img scripts/screenshots.sh # writes elsewhere
|
|
#
|
|
# Variables: OUT, HUB_PORT (18880), PEER_PORT (18881), LOGIN_PORT (18882), CHROME,
|
|
# PUPPETEER_CORE (default: newest Chrome in ~/.cache/puppeteer and puppeteer-core in
|
|
# ~/.claude/tools/node_modules). Needs go, node, curl, openssl and Chrome. No network use.
|
|
# Idempotent: it builds into a temporary directory, kills what it started (by PID) when done
|
|
# and overwrites the same file names. oxipng/pngquant are used when installed.
|
|
set -euo pipefail
|
|
|
|
root=$(cd "$(dirname "$0")/.." && pwd)
|
|
out=${OUT:-$root/docs/img}
|
|
hub_port=${HUB_PORT:-18880}
|
|
peer_port=${PEER_PORT:-18881}
|
|
login_port=${LOGIN_PORT:-18882}
|
|
|
|
work=$(mktemp -d)
|
|
pids=()
|
|
cleanup() {
|
|
for p in "${pids[@]}"; do kill "$p" 2>/dev/null || true; done
|
|
for p in "${pids[@]}"; do wait "$p" 2>/dev/null || true; done
|
|
rm -rf "$work"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
for port in "$hub_port" "$peer_port" "$login_port"; do
|
|
if curl -fsS -m 1 "http://127.0.0.1:$port/api/health" >/dev/null 2>&1; then
|
|
echo "port $port is already in use; stop that instance first" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
export TZ=UTC
|
|
# Hidden demo-only switch: reserved ranges count as public for the second firewall (see internal/enforce/policy.go).
|
|
export URUTAU_DEMO_RESERVED_PUBLIC=1
|
|
mkdir -p "$out" "$work/bin"
|
|
(cd "$root" && go build -trimpath -o "$work/bin/urutau" ./cmd/urutau && go build -o "$work/bin/demo" ./scripts/screenshots/demo)
|
|
urutau="$work/bin/urutau"
|
|
demo="$work/bin/demo"
|
|
|
|
# Demo geolocation base and logs (relative to "now").
|
|
"$demo" geo "$work/geo"
|
|
"$demo" logs "$work/hub/logs" edge-1 1
|
|
"$demo" logs "$work/peer/logs" edge-2 2
|
|
"$demo" egress "$work/hub/egress"
|
|
"$demo" check "$work"/hub/logs/* "$work"/peer/logs/* "$work"/hub/egress/* # fails on any IP outside the reserved ranges
|
|
|
|
export URUTAU_PEER_TOKEN=$(openssl rand -base64 48 | tr -d '\n')
|
|
start() { # start name port dir [extra flags...]
|
|
local name=$1 port=$2 dir=$3; shift 3
|
|
"$urutau" serve --name "$name" --bind "127.0.0.1:$port" --data-dir "$dir/data" \
|
|
--traefik-log "$dir/logs/access.log" --auth-log "$dir/logs/auth.log" --fail2ban-log "$dir/logs/fail2ban.log" \
|
|
--geo-dir "$work/geo" --geo-update 0 --insecure-no-auth "$@" > "$dir.log" 2>&1 &
|
|
pids+=($!)
|
|
}
|
|
start edge-2 "$peer_port" "$work/peer" --location "39.0438,-77.4874,edge-2"
|
|
start edge-1 "$hub_port" "$work/hub" --location "50.1109,8.6821,edge-1" \
|
|
--enforce observe --egress on --egress-log "$work/hub/egress/egress.log" --egress-containers "$work/hub/egress/containers.map" \
|
|
--egress-workloads "ciberlab=name:ciberlab:scanner" --peer "edge-2=http://127.0.0.1:$peer_port"
|
|
|
|
# A third, short-lived instance with authentication on, only for the login page.
|
|
mkdir -p "$work/login/data"
|
|
URUTAU_TOKEN=$(openssl rand -base64 48 | tr -d '\n') URUTAU_PEER_TOKEN= "$urutau" serve --name edge-1 \
|
|
--bind "127.0.0.1:$login_port" --data-dir "$work/login/data" --traefik-log "" --auth-log "" --fail2ban-log "" \
|
|
--geo-dir "$work/geo" --geo-update 0 > "$work/login.log" 2>&1 &
|
|
pids+=($!)
|
|
|
|
for port in "$hub_port" "$peer_port" "$login_port"; do
|
|
ok=0
|
|
for _ in $(seq 1 150); do
|
|
curl -fsS "http://127.0.0.1:$port/api/health" >/dev/null 2>&1 && { ok=1; break; }
|
|
sleep 0.2
|
|
done
|
|
[ "$ok" = 1 ] || { echo "instance on port $port did not start:" >&2; tail -20 "$work"/*.log >&2; exit 1; }
|
|
done
|
|
# wait until the hub has read the backfill (the request counter stops growing)
|
|
prev=-1
|
|
for _ in $(seq 1 240); do
|
|
n=$(curl -fsS "http://127.0.0.1:$hub_port/api/v1/summary?range=30d" 2>/dev/null | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{console.log(JSON.parse(s).totals.requests||0)}catch{console.log(0)}})' || echo 0)
|
|
[ "${n:-0}" -gt 1000 ] && [ "$n" = "$prev" ] && break
|
|
prev=$n
|
|
sleep 1
|
|
done
|
|
|
|
# New events keep arriving while the pages are captured.
|
|
"$demo" live 900 "$work/hub/logs:edge-1" "$work/peer/logs:edge-2" > "$work/live.log" 2>&1 &
|
|
pids+=($!)
|
|
sleep 6
|
|
|
|
node "$root/scripts/screenshots/shots.mjs" "http://127.0.0.1:$hub_port" "http://127.0.0.1:$login_port" "$out"
|
|
|
|
if command -v oxipng >/dev/null; then oxipng -q -o 3 --strip safe "$out"/*.png
|
|
elif command -v pngquant >/dev/null; then for f in "$out"/*.png; do pngquant --quality 90-100 --force --output "$f" "$f"; done; fi
|
|
echo "screenshots written to $out"
|