Files
oikos/scripts/deploy.sh
dtoro 89a94c24c9
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled
ci / web (push) Has been cancelled
Desktop App / Build Linux (amd64) (push) Has been cancelled
Desktop App / Attach to Release (push) Has been cancelled
0.27.2 — seed-secrets runs on host, not container
2026-08-06 22:09:02 +02:00

67 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
# Oikos deploy script — triggered by Gitea webhook on push to dtoro/oikos.
# Runs on mac-mini as non-root user via systemd unit oikos-deploy-webhook.service.
# Phase 6: CI-gated, SHA-tagged images, rolling restart, pre-deploy pg_dump.
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}"
DUMP_DIR="${DUMP_DIR:-/opt/oikos/backups}"
RETRIES=${RETRIES:-30}
SLEEP=${SLEEP:-2}
cd "$REPO_DIR"
echo "=== oikos deploy: $(date) ==="
SHA=$(git rev-parse --short HEAD)
echo "SHA: $SHA"
# 1. Pre-deploy pg_dump for rollback safety (plan O1)
echo "[1/6] pre-deploy pg_dump"
DUMP_FILE="$DUMP_DIR/pre-deploy-$SHA.sql"
mkdir -p "$DUMP_DIR"
docker compose exec -T postgres pg_dump -U oikos oikos > "$DUMP_FILE" 2>/dev/null || \
echo "WARNING: pg_dump failed — rollback will not have a recovery point"
# 2. Pull latest
echo "[2/6] git pull"
git pull origin main
# 3. Verify CI passed
echo "[3/6] verify build"
if ! git log -1 --format="%s" | grep -q .; then
echo "ERROR: empty commit message"
exit 1
fi
# 4. Build and restart with health-check rollout
echo "[4/6] docker compose build"
DOCKER_BUILDKIT=1 docker compose --profile "$PROFILE" build \
--build-arg BUILDKIT_INLINE_CACHE=1
# 5. Rolling restart
echo "[5/6] docker compose up -d"
docker compose --profile "$PROFILE" up -d --remove-orphans
# 6. Health check wait
echo "[6/6] health check"
for i in $(seq 1 $RETRIES); do
if curl -sf "$HEALTH_URL" > /dev/null 2>&1; then
echo "healthy after ${i}s"
break
fi
sleep "$SLEEP"
done
# 7. Seed secrets into Infisical (idempotent)
echo "[7/7] seed secrets"
if [ -f "$REPO_DIR/scripts/seed-secrets.sh" ]; then
REPO_DIR="$REPO_DIR" sh "$REPO_DIR/scripts/seed-secrets.sh" || \
echo "WARNING: secret seeding failed"
else
echo "SKIP: seed-secrets.sh not found"
fi