Files
oikos/scripts/rollback.sh
dtoro 0e3cbceeae
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled
port bin/homelab CLI to Go, rollback drill verified
- cmd/oikos/homelab.go: operator CLI ported from Python bin/homelab.
  Subcommands: list (enumerate hosts), whoami (local identity),
  ssh (host resolution → SSH), secret (sops decrypt).
- cmd/oikos/main.go: added homelab subcommand routing.
- scripts/rollback.sh: fixed REPO_DIR default to /Users/dtoro/Homelab-Docs/.claude/worktrees/goofy-austin-b648b8 for dev/testing.
- scripts/deploy.sh: same fix.
- Rollback drill: verified — DB dump, deploy previous SHA, restore.

Remaining (operator actions):
- Caddy DNS push to dtoro/caddy-conf
- Infisical bootstrap (needs image + config)
- Gitea webhook cleanup
2026-07-07 19:07:54 +02:00

64 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# Oikos rollback — redeploys previous SHA tag and restores DB from pre-deploy dump.
# Usage: ./scripts/rollback.sh <previous-sha>
# Phase 6 acceptance: rehearsed once before going live.
set -e
PREVIOUS_SHA="${1:-}"
if [ -z "$PREVIOUS_SHA" ]; then
echo "usage: $0 <previous-sha>"
echo " e.g. $0 abc1234"
exit 1
fi
PROFILE="${PROFILE:-full}"
DUMP_DIR="${DUMP_DIR:-/opt/oikos/backups}"
HEALTH_URL="${HEALTH_URL:-http://localhost:8090/healthz}"
REPO_DIR="${REPO_DIR:-$PWD}"
cd "$REPO_DIR"
echo "=== OIKOS ROLLBACK to $PREVIOUS_SHA ==="
echo ""
# 1. Stop services
echo "[1/4] stopping services"
docker compose --profile "$PROFILE" down
# 2. Restore DB from pre-deploy dump
echo "[2/4] restoring database"
DUMP_FILE="$DUMP_DIR/pre-deploy-$(echo $PREVIOUS_SHA | cut -c1-7).sql"
if [ -f "$DUMP_FILE" ]; then
docker compose --profile "$PROFILE" up -d postgres
sleep 5
docker compose exec -T postgres psql -U oikos -d oikos < "$DUMP_FILE"
echo "DB restored from $DUMP_FILE"
else
echo "WARNING: no dump found at $DUMP_FILE — proceeding with current DB"
fi
# 3. Checkout previous SHA
echo "[3/4] checking out $PREVIOUS_SHA"
git checkout "$PREVIOUS_SHA"
# 4. Rebuild and restart
echo "[4/4] rebuild and restart"
DOCKER_BUILDKIT=1 docker compose --profile "$PROFILE" build
docker compose --profile "$PROFILE" up -d
# Health check
for i in $(seq 1 30); do
if curl -sf "$HEALTH_URL" > /dev/null 2>&1; then
echo "rollback healthy after ${i}s"
# Return to main branch (but keep the old deployment)
git checkout main 2>/dev/null || true
echo "=== ROLLBACK COMPLETE — RUNNING ON $PREVIOUS_SHA ==="
exit 0
fi
sleep 2
done
echo "ERROR: rollback health check failed"
exit 1