- 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
53 lines
1.4 KiB
Bash
Executable File
53 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# Oikos deploy script — triggered by Gitea webhook on push to dtoro/Homelab-Docs.
|
|
# Runs on mac-mini as non-root user via systemd unit oikos-deploy-webhook.service.
|
|
# Phase 6: CI-gated, SHA-tagged images, rolling restart.
|
|
|
|
set -e
|
|
|
|
REPO_DIR="${REPO_DIR:-$PWD}"
|
|
COMPOSE_FILE="${COMPOSE_FILE:-docker-compose.yml}"
|
|
PROFILE="${PROFILE:-full}"
|
|
HEALTH_URL="${HEALTH_URL:-http://localhost:8090/healthz}"
|
|
RETRIES=${RETRIES:-30}
|
|
SLEEP=${SLEEP:-2}
|
|
|
|
cd "$REPO_DIR"
|
|
|
|
echo "=== oikos deploy: $(date) ==="
|
|
echo "SHA: $(git rev-parse --short HEAD)"
|
|
|
|
# 1. Pull latest
|
|
echo "[1/5] git pull"
|
|
git pull origin main
|
|
|
|
# 2. Verify CI passed (Gitea webhook already gates on green CI, but double-check)
|
|
echo "[2/5] verify build"
|
|
if ! git log -1 --format="%s" | grep -q .; then
|
|
echo "ERROR: empty commit message"
|
|
exit 1
|
|
fi
|
|
|
|
# 3. Build and restart with health-check rollout
|
|
echo "[3/5] docker compose build"
|
|
SHA=$(git rev-parse --short HEAD)
|
|
DOCKER_BUILDKIT=1 docker compose --profile "$PROFILE" build \
|
|
--build-arg BUILDKIT_INLINE_CACHE=1
|
|
|
|
# 4. Rolling restart (stop → start, not up -d which skips rebuild)
|
|
echo "[4/5] docker compose up -d"
|
|
docker compose --profile "$PROFILE" up -d --remove-orphans
|
|
|
|
# 5. Health check wait
|
|
echo "[5/5] health check"
|
|
for i in $(seq 1 $RETRIES); do
|
|
if curl -sf "$HEALTH_URL" > /dev/null 2>&1; then
|
|
echo "healthy after ${i}s"
|
|
exit 0
|
|
fi
|
|
sleep "$SLEEP"
|
|
done
|
|
|
|
echo "ERROR: health check failed after $((RETRIES * SLEEP))s"
|
|
exit 1
|