Adds glitchtip-web + glitchtip-worker to docker-compose.prod.yml using the shared postgres/redis services. Caddy proxies errors.gendsgn.ru to glitchtip-web:8080 with auto-TLS. Bootstrap script handles DB creation and first-run setup idempotently. Env contract: GLITCHTIP_DB_PASS, GLITCHTIP_SECRET in .env; GLITCHTIP_DSN and NEXT_PUBLIC_GLITCHTIP_DSN populated after UI setup.
108 lines
4.2 KiB
Bash
108 lines
4.2 KiB
Bash
#!/usr/bin/env bash
|
|
# bootstrap_glitchtip.sh
|
|
# One-shot bootstrap for GlitchTip on the VPS.
|
|
#
|
|
# Run ONCE manually after merging feat/204-glitchtip-infra.
|
|
# Do NOT add to deploy.yml — this is idempotent setup, not a recurring step.
|
|
#
|
|
# Usage (on VPS via SSH):
|
|
# cd /opt/gendesign
|
|
# # Ensure GLITCHTIP_DB_PASS and GLITCHTIP_SECRET are set in .env
|
|
# bash scripts/bootstrap_glitchtip.sh
|
|
#
|
|
# After running:
|
|
# 1. docker compose -p gendesign -f docker-compose.prod.yml exec glitchtip-web ./manage.py createsuperuser
|
|
# 2. Log in to https://errors.gendsgn.ru → create org "gendesign"
|
|
# 3. Create projects: "backend", "frontend"
|
|
# 4. Copy DSNs → add to /opt/gendesign/backend/.env (GLITCHTIP_DSN)
|
|
# and /opt/gendesign/frontend/.env or .env.runtime (NEXT_PUBLIC_GLITCHTIP_DSN)
|
|
# 5. Recreate affected containers:
|
|
# docker compose -p gendesign -f docker-compose.prod.yml up -d --force-recreate --no-deps backend
|
|
|
|
set -euo pipefail
|
|
|
|
COMPOSE_FILE="docker-compose.prod.yml"
|
|
COMPOSE_PROJECT="gendesign"
|
|
COMPOSE="docker compose -p $COMPOSE_PROJECT -f $COMPOSE_FILE"
|
|
|
|
# ── Load .env.runtime for GLITCHTIP_DB_PASS / POSTGRES_* ──────────────────
|
|
if [ -f ".env" ]; then
|
|
set -a; source .env; set +a
|
|
fi
|
|
if [ -f "backend/.env.runtime" ]; then
|
|
set -a; source backend/.env.runtime; set +a
|
|
fi
|
|
|
|
: "${GLITCHTIP_DB_PASS:?GLITCHTIP_DB_PASS not set — add to .env or export}"
|
|
: "${POSTGRES_USER:?POSTGRES_USER not set}"
|
|
: "${POSTGRES_PASSWORD:?POSTGRES_PASSWORD not set}"
|
|
: "${POSTGRES_DB:?POSTGRES_DB not set}"
|
|
|
|
echo "==> Ensuring postgres service is healthy..."
|
|
for i in $(seq 1 30); do
|
|
if $COMPOSE exec -T postgres pg_isready -U "$POSTGRES_USER" -q; then
|
|
break
|
|
fi
|
|
echo " Waiting for postgres... ($i/30)"
|
|
sleep 2
|
|
done
|
|
|
|
# ── Create glitchtip DB + user (idempotent) ────────────────────────────────
|
|
echo "==> Creating glitchtip database and user (idempotent)..."
|
|
$COMPOSE exec -T postgres psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" \
|
|
-v ON_ERROR_STOP=on <<SQL
|
|
DO \$\$
|
|
BEGIN
|
|
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'glitchtip') THEN
|
|
CREATE ROLE glitchtip LOGIN PASSWORD '$GLITCHTIP_DB_PASS';
|
|
RAISE NOTICE 'Created role glitchtip';
|
|
ELSE
|
|
RAISE NOTICE 'Role glitchtip already exists';
|
|
END IF;
|
|
END
|
|
\$\$;
|
|
|
|
SELECT 'CREATE DATABASE glitchtip OWNER glitchtip'
|
|
WHERE NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = 'glitchtip')
|
|
\gexec
|
|
SQL
|
|
|
|
# ── Start GlitchTip containers ─────────────────────────────────────────────
|
|
echo "==> Pulling glitchtip image..."
|
|
$COMPOSE pull glitchtip-web glitchtip-worker
|
|
|
|
echo "==> Starting glitchtip-web and glitchtip-worker..."
|
|
$COMPOSE up -d glitchtip-web glitchtip-worker
|
|
|
|
# ── Wait for glitchtip-web to become healthy ───────────────────────────────
|
|
echo "==> Waiting for glitchtip-web to become healthy (up to 60s)..."
|
|
for i in $(seq 1 30); do
|
|
if $COMPOSE exec -T glitchtip-web curl -fsS http://localhost:8080/healthz/ >/dev/null 2>&1; then
|
|
echo " glitchtip-web is healthy."
|
|
break
|
|
fi
|
|
echo " Waiting... ($i/30)"
|
|
sleep 2
|
|
done
|
|
|
|
echo ""
|
|
echo "==> Bootstrap complete."
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Create superuser:"
|
|
echo " $COMPOSE exec glitchtip-web ./manage.py createsuperuser"
|
|
echo ""
|
|
echo " 2. Log in to https://errors.gendsgn.ru"
|
|
echo " - Create organization: gendesign"
|
|
echo " - Create project: backend (Platform: Python)"
|
|
echo " - Create project: frontend (Platform: JavaScript / Browser)"
|
|
echo ""
|
|
echo " 3. Copy DSNs from each project's Settings → DSN"
|
|
echo " - Add GLITCHTIP_DSN=<backend-dsn> to /opt/gendesign/backend/.env"
|
|
echo " - Add NEXT_PUBLIC_GLITCHTIP_DSN=<frontend-dsn> to /opt/gendesign/backend/.env or .env"
|
|
echo ""
|
|
echo " 4. Recreate services to pick up new DSNs:"
|
|
echo " $COMPOSE up -d --force-recreate --no-deps backend"
|
|
echo " $COMPOSE up -d --force-recreate --no-deps worker beat"
|
|
echo ""
|
|
echo " 5. Verify: trigger a test exception and confirm it appears in GlitchTip."
|