fix(ops): harden deploy/restore/verify scripts
Some checks failed
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / ruff (push) Successful in 9s
CI / pytest (push) Has been cancelled

- deploy.sh: add DB health wait before migrations, prune old Docker images
- restore.sh: add redis-exporter to stop list, replace sleep with DB health wait
- verify-server.sh: add redis-exporter to expected containers, add Sentry + Redis exporter checks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 00:23:14 +01:00
parent 35d1559162
commit 93a2d9baff
3 changed files with 85 additions and 15 deletions

View File

@@ -44,24 +44,46 @@ if ! $COMPOSE up -d --build; then
exit 2
fi
# ── 3. Run database migrations ───────────────────────────────────────────────
# ── 3. Wait for DB to be healthy before running migrations ──────────────────
log "Waiting for database to be healthy …"
for i in $(seq 1 12); do
if $COMPOSE exec -T db pg_isready -U orion_user -d orion_db > /dev/null 2>&1; then
log "Database is ready (attempt $i/12)"
break
fi
if [ "$i" -eq 12 ]; then
log "ERROR: database not ready after 60s"
exit 3
fi
sleep 5
done
# ── 4. Run database migrations ───────────────────────────────────────────────
log "Running database migrations …"
if ! $COMPOSE exec -T -e PYTHONPATH=/app api python -m alembic upgrade heads; then
log "ERROR: alembic migration failed"
exit 3
fi
# ── 4. Health check with retries ─────────────────────────────────────────────
# ── 5. Health check with retries ─────────────────────────────────────────────
log "Waiting for health check ($HEALTH_URL) …"
for i in $(seq 1 "$HEALTH_RETRIES"); do
if curl -sf "$HEALTH_URL" > /dev/null 2>&1; then
log "Health check passed (attempt $i/$HEALTH_RETRIES)"
log "Deploy complete."
exit 0
break
fi
log "Health check attempt $i/$HEALTH_RETRIES failed, retrying in ${HEALTH_INTERVAL}s …"
sleep "$HEALTH_INTERVAL"
done
log "ERROR: health check failed after $HEALTH_RETRIES attempts"
exit 4
if ! curl -sf "$HEALTH_URL" > /dev/null 2>&1; then
log "ERROR: health check failed after $HEALTH_RETRIES attempts"
exit 4
fi
# ── 6. Clean up old Docker images ───────────────────────────────────────────
log "Pruning unused Docker images …"
docker image prune -f --filter "until=72h" > /dev/null 2>&1 || true
log "Deploy complete."
exit 0