#!/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 set -euo pipefail image=${1:?usage: smoke-image.sh } 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 [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 '&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"