#!/usr/bin/env bash # Checks the dedicated server packaging (issue N7) end to end, in Docker: # - `docker compose up` in packaging/docker builds the image and starts the server, # - the container reports healthy through GET /health, # - it runs as a non-root user on a read-only filesystem, # - a real headless client joins it over UDP and plays from the lobby into the drop, # - `docker compose stop` stops it cleanly: SIGTERM becomes a logged, orderly stop. # Takes about a minute and a half. Leaves the tidewall-server:dev image, removes the # container. SERVER_CHECK_PORT picks the UDP port (default 24675). set -uo pipefail repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$repo" export TIDEWALL_PORT="${SERVER_CHECK_PORT:-24675}" compose=(docker compose -f packaging/docker/compose.yaml) out="$repo/build/server-check" mkdir -p "$out" fail() { echo "server-package-check: $1" >&2 "${compose[@]}" logs --no-color 2>/dev/null | tail -n 8 >&2 "${compose[@]}" down --timeout 20 >/dev/null 2>&1 exit 1 } nice -n 15 "${compose[@]}" up -d --build --quiet-pull >"$out/up.log" 2>&1 || { cat "$out/up.log" >&2; fail "compose up failed"; } health="" for _ in $(seq 1 30); do health="$(docker inspect -f '{{.State.Health.Status}}' tidewall-server 2>/dev/null)" [[ "$health" == "healthy" ]] && break sleep 2 done [[ "$health" == "healthy" ]] || fail "the container never became healthy (it is '$health')" [[ "$(docker exec tidewall-server id -u)" != "0" ]] || fail "the server runs as root" docker exec tidewall-server touch /opt/tidewall/game/probe 2>/dev/null && fail "the game's files are writable" docker exec tidewall-server touch /etc/probe 2>/dev/null && fail "the root filesystem is writable" reply="$(docker exec tidewall-server bash -c 'exec 3<>/dev/tcp/127.0.0.1/24650; printf "GET /health HTTP/1.0\r\n\r\n" >&3; cat <&3')" grep -q '"status":"ok"' <<<"$reply" || fail "GET /health said: $reply" nice -n 15 tools/godot.sh -- --connect="127.0.0.1:$TIDEWALL_PORT" --name=Harbour --autoplay --client-seconds=45 >"$out/client.log" 2>&1 report="$(grep -m1 '"event":"client"' "$out/client.log" || true)" grep -q '"joined":true' <<<"$report" || fail "the client never joined: ${report:-no report}" grep -q '"phases":\["lobby","countdown","drop"' <<<"$report" || fail "the client didn't get from the lobby into the drop: $report" grep -q '"bad_packets":0' <<<"$report" || fail "the client got packets it couldn't read: $report" "${compose[@]}" stop --timeout 20 >/dev/null 2>&1 code="$(docker inspect -f '{{.State.ExitCode}}' tidewall-server)" "${compose[@]}" logs --no-color >"$out/server.log" 2>&1 "${compose[@]}" down --timeout 20 >/dev/null 2>&1 [[ "$code" == "0" ]] || fail "the server exited $code when stopped" grep -q '"event":"player_joined".*"name":"Harbour"' "$out/server.log" || fail "the server never saw the client join" grep -q '"event":"stopping","reason":"stop file"' "$out/server.log" || fail "SIGTERM didn't become a clean stop" grep -q '"errors":0,"event":"stop","exit_code":0' "$out/server.log" || fail "the server didn't log a clean stop" echo "server-package-check: ok (healthy, non-root, read-only, joined over UDP into the drop, stopped cleanly on SIGTERM)" echo " $report"