#!/usr/bin/env bash
set -euo pipefail

APP_PORT="${APP_PORT:-7000}"
REDIS_URL="${REDIS_URL:-redis://127.0.0.1:6379/0}"

redis-cli -u "${REDIS_URL}" ping | grep -q PONG
mongosh "${MONGO_URI}" --quiet --eval "db.adminCommand({ ping: 1 }).ok" | grep -q 1
python - <<'PY'
import os
import sys
import urllib.request

port = os.getenv("APP_PORT", "7000")
url = f"http://127.0.0.1:{port}/login"
try:
    with urllib.request.urlopen(url, timeout=5) as response:
        if response.status >= 400:
            raise RuntimeError(f"unexpected status {response.status}")
except Exception as exc:
    print(exc, file=sys.stderr)
    raise
PY
