Release / Plan (reuse the published image?) (push) Successful in 4s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 1m29s
CI / Tests (Linux, race detector) (push) Failing after 1m48s
CI / Dependency audit (push) Successful in 21s
Release / ci (push) Failing after 1m50s
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Skipped
Release / Gitea release (push) Skipped
Always-on Go service (stdlib only) that follows the Traefik JSON access log, the sshd log and the fail2ban log of a host, classifies attacks, scores sources, keeps bounded aggregates with snapshots, and serves an embedded dashboard with live updates, offline geolocation (DB-IP Lite), privacy-friendly traffic analytics, an exportable blocklist and token-authenticated federation between instances. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
3.6 KiB
Bash
Executable File
59 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Smoke-tests an Urutau image: the HEALTHCHECK command works, the API is closed
|
|
# without a token and open with it, the peer token only opens the export, the
|
|
# dashboard is served, urutau doctor reports a version, the daemon is not root
|
|
# and SIGTERM stops it cleanly with exit 0.
|
|
# The image has no curl: HTTP checks use the BusyBox wget that Alpine ships.
|
|
# Everything runs through `docker exec`, so no port has to be reachable from the
|
|
# CI job container. The container is always removed.
|
|
#
|
|
# scripts/smoke-image.sh <image-ref>
|
|
set -euo pipefail
|
|
|
|
image=${1:?usage: smoke-image.sh <image-ref>}
|
|
name="urutau-smoke-$$-$RANDOM"
|
|
token=$(head -c 40 /dev/urandom | base64 | tr -d '=+/\n')
|
|
peer=$(head -c 40 /dev/urandom | base64 | tr -d '=+/\n')
|
|
trap 'docker rm -f "$name" >/dev/null 2>&1 || true' EXIT
|
|
fail() { echo "smoke: $*" >&2; docker logs "$name" >&2 2>&1 || true; exit 1; }
|
|
base=http://127.0.0.1:8790
|
|
# status <url> [header]: HTTP status code of a GET (wget -S prints the response headers)
|
|
status() {
|
|
local url=$1; shift
|
|
docker exec "$name" wget -S -q -O /dev/null "$@" "$url" 2>&1 | awk '/^ *HTTP\//{c=$2} END{print c}'
|
|
}
|
|
get() { local url=$1; shift; docker exec "$name" wget -q -O - "$@" "$url"; }
|
|
|
|
# No log files are mounted: the sources wait for them. docker create + start
|
|
# instead of a bind mount, which the daemon may not see from a CI job.
|
|
docker create --name "$name" -e URUTAU_TOKEN="$token" -e URUTAU_PEER_TOKEN="$peer" -e URUTAU_GEO_UPDATE=0 "$image" >/dev/null
|
|
docker start "$name" >/dev/null
|
|
for _ in $(seq 1 30); do
|
|
docker exec "$name" urutau healthcheck >/dev/null 2>&1 && break
|
|
sleep 1
|
|
done
|
|
docker exec "$name" urutau healthcheck || fail "urutau healthcheck failed"
|
|
out=$(get "$base/api/health") || fail "/api/health did not answer"
|
|
grep -q '"status":"ok"' <<<"$out" || fail "/api/health is not ok"
|
|
grep -q '"version"' <<<"$out" && fail "/api/health must not expose the version"
|
|
[ "$(status "$base/api/v1/summary")" = 401 ] || fail "/api/v1/summary without a token must answer 401"
|
|
[ "$(status "$base/api/v1/summary" --header "Authorization: Bearer $peer")" = 403 ] || fail "the peer token on /api/v1/summary must answer 403"
|
|
out=$(get "$base/api/v1/summary" --header "Authorization: Bearer $token") || fail "authenticated summary failed"
|
|
grep -q '"totals"' <<<"$out" || fail "summary has no totals"
|
|
out=$(get "$base/api/v1/peer/export?range=1h" --header "Authorization: Bearer $peer") || fail "peer export failed"
|
|
grep -q '"summary"' <<<"$out" || fail "peer export has no summary"
|
|
[ "$(status "$base/api/v1/peer/export" --header "Authorization: Bearer $token")" = 401 ] || fail "the user token must not open the peer export"
|
|
out=$(get "$base/login") || fail "login page did not answer"
|
|
grep -qi '<!doctype html' <<<"$out" || fail "login page is not served"
|
|
out=$(get "$base/" --header "Authorization: Bearer $token") || fail "dashboard did not answer"
|
|
grep -qi '<!doctype html' <<<"$out" || fail "dashboard is not served"
|
|
out=$(docker exec "$name" urutau doctor --json) || { echo "$out" >&2; fail "urutau doctor --json failed"; }
|
|
grep -q '"version"' <<<"$out" || fail "urutau doctor --json has no version"
|
|
[ "$(docker inspect -f '{{if .Config.Healthcheck}}yes{{end}}' "$name")" = yes ] || fail "image has no HEALTHCHECK"
|
|
[ "$(docker exec "$name" id -u)" != 0 ] || fail "daemon runs as root"
|
|
docker exec "$name" sh -c 'command -v curl' >/dev/null 2>&1 && fail "the image must not ship curl"
|
|
docker stop -t 10 "$name" >/dev/null
|
|
code=$(docker inspect -f '{{.State.ExitCode}}' "$name")
|
|
[ "$code" = 0 ] || fail "exit code $code after SIGTERM (expected 0: SIGTERM must stop serve)"
|
|
echo "smoke: $image ok"
|