Files
git.stella-ops.org/devops/tools/run-attestor-ttl-validation.sh
2026-01-25 23:27:41 +02:00

86 lines
2.3 KiB
Bash

#!/usr/bin/env bash
# Runs live TTL validation for Attestor dedupe stores against local PostgreSQL/Valkey.
set -euo pipefail
if ! command -v docker >/dev/null 2>&1; then
echo "docker CLI is required. Install Docker Desktop or ensure docker is on PATH." >&2
exit 1
fi
if ! docker compose version >/dev/null 2>&1; then
if command -v docker-compose >/dev/null 2>&1; then
compose_cmd="docker-compose"
else
echo "docker compose plugin (or docker-compose) is required." >&2
exit 1
fi
else
compose_cmd="docker compose"
fi
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
compose_file="$(mktemp -t attestor-ttl-compose-XXXXXX.yaml)"
cleanup() {
$compose_cmd -f "$compose_file" down -v >/dev/null 2>&1 || true
rm -f "$compose_file"
}
trap cleanup EXIT
cat >"$compose_file" <<'YAML'
services:
postgres:
image: postgres:18.1-alpine
environment:
POSTGRES_USER: attestor
POSTGRES_PASSWORD: attestor
POSTGRES_DB: attestor_ttl
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U attestor -d attestor_ttl"]
interval: 5s
timeout: 3s
retries: 20
valkey:
image: valkey/valkey:9-alpine
command: ["valkey-server", "--save", "", "--appendonly", "no"]
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "valkey-cli", "ping"]
interval: 5s
timeout: 3s
retries: 20
YAML
echo "Starting PostgreSQL and Valkey containers..."
$compose_cmd -f "$compose_file" up -d
wait_for_port() {
local host=$1
local port=$2
local name=$3
for attempt in {1..60}; do
if (echo > /dev/tcp/"$host"/"$port") >/dev/null 2>&1; then
echo "$name is accepting connections."
return 0
fi
sleep 1
done
echo "Timeout waiting for $name on $host:$port" >&2
return 1
}
wait_for_port 127.0.0.1 5432 "PostgreSQL"
wait_for_port 127.0.0.1 6379 "Valkey"
export ATTESTOR_LIVE_POSTGRES_URI="${ATTESTOR_LIVE_POSTGRES_URI:-Host=127.0.0.1;Port=5432;Database=attestor_ttl;Username=attestor;Password=attestor}"
export ATTESTOR_LIVE_VALKEY_URI="${ATTESTOR_LIVE_VALKEY_URI:-127.0.0.1:6379}"
echo "Running live TTL validation tests..."
dotnet test "$repo_root/src/Attestor/StellaOps.Attestor.sln" --no-build --filter "Category=LiveTTL" "$@"
echo "Live TTL validation complete. Shutting down containers."