44 lines
1.4 KiB
Bash
Executable File
44 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Builds and starts the production stack under a throwaway project name with
|
|
# generated secrets, checks it, then removes it (containers and volumes).
|
|
# deploy/check.sh from the repository root or deploy/
|
|
# Exits non-zero if any check fails. Needs Docker with Compose v2.
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")"
|
|
project="deadhead-check"
|
|
env_file="$(mktemp)"
|
|
secret() { node -e 'console.log(require("crypto").randomBytes(+process.argv[1]).toString("base64url"))' "$1"; }
|
|
cat > "$env_file" <<EOF
|
|
PUBLIC_URL=http://localhost:8080
|
|
POSTGRES_PASSWORD=$(secret 18)
|
|
BETTER_AUTH_SECRET=$(secret 32)
|
|
EOF
|
|
compose() { docker compose -p "$project" --env-file "$env_file" "$@"; }
|
|
cleanup() {
|
|
compose down -v --remove-orphans >/dev/null 2>&1 || true
|
|
rm -f "$env_file"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
echo "Building and starting the stack…"
|
|
compose up -d --build --wait --wait-timeout 180
|
|
|
|
fail=0
|
|
check() {
|
|
local name="$1" url="$2" expect="$3" body
|
|
body="$(compose exec -T server node -e "fetch('$url').then(r => r.text().then(t => console.log(r.status + ' ' + t)))")"
|
|
if [[ "$body" == $expect ]]; then
|
|
echo "ok $name: $body"
|
|
else
|
|
echo "FAIL $name: $body"
|
|
fail=1
|
|
fi
|
|
}
|
|
|
|
# Step 13.1: the server, with migrations applied, answers health and time.
|
|
check "health" "http://127.0.0.1:3000/api/health" '200 {"status":"ok"}'
|
|
check "server time" "http://127.0.0.1:3000/api/time" '200 {"realTime":*'
|
|
|
|
exit "$fail"
|