56 lines
2.6 KiB
Bash
56 lines
2.6 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Stable-only production updater. Candidate slots are managed exclusively by
|
|
# their isolated release command and Supervisor; this controller never starts
|
|
# or reconciles a candidate service.
|
|
BASE_DIR="${BASE_DIR:-/home/m/assistant-deploy}"
|
|
REPO_DIR="${REPO_DIR:-$BASE_DIR/repo}"
|
|
ENV_FILE="${ENV_FILE:-$BASE_DIR/production-compose.env}"
|
|
COMPOSE_FILE="$REPO_DIR/deploy/docker-compose.prod.yml"
|
|
LOG_FILE="${LOG_FILE:-$BASE_DIR/deploy.log}"
|
|
LOCK_FILE="${LOCK_FILE:-/tmp/assistant-stable-deploy.lock}"
|
|
stable_services=(postgres core-runtime continuity-runtime commit-runtime cognitive-worker creator-web notification-receiver research-runtime agent-worker work-graph-runtime)
|
|
|
|
exec 9>"$LOCK_FILE"
|
|
flock -n 9 || exit 0
|
|
log() { printf '%s %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$*" >>"$LOG_FILE"; }
|
|
fail() { log "FAILED: $*"; exit 1; }
|
|
compose() { docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" "$@"; }
|
|
|
|
cd "$REPO_DIR"
|
|
git fetch --prune origin main >>"$LOG_FILE" 2>&1
|
|
git merge --ff-only origin/main >>"$LOG_FILE" 2>&1 || fail "stable checkout is not a fast-forward to origin/main"
|
|
revision="$(git rev-parse HEAD)"
|
|
[[ "$revision" =~ ^[0-9a-f]{40}$ ]] || fail "invalid source revision"
|
|
|
|
if ! REPO_DIR="$REPO_DIR" ENV_FILE="$ENV_FILE" bash "$REPO_DIR/deploy/apply-migrations.sh" >>"$LOG_FILE" 2>&1; then
|
|
fail "migration application failed"
|
|
fi
|
|
compose config >/dev/null 2>>"$LOG_FILE" || fail "stable compose config validation failed"
|
|
|
|
all_current=1
|
|
for service in "${stable_services[@]}"; do
|
|
container="assistant-${service}-1"
|
|
label="$(docker inspect "$container" --format '{{index .Config.Labels "org.opencontainers.image.revision"}}' 2>/dev/null || true)"
|
|
[[ "$label" == "$revision" ]] || all_current=0
|
|
done
|
|
if [[ "$all_current" == 1 ]]; then log "SKIP stable revision=$revision"; exit 0; fi
|
|
|
|
log "BUILD stable revision=$revision"
|
|
ASSISTANT_SOURCE_REVISION="$revision" compose build --build-arg "SOURCE_REVISION=$revision" "${stable_services[@]}" >>"$LOG_FILE" 2>&1
|
|
log "UP stable revision=$revision"
|
|
ASSISTANT_SOURCE_REVISION="$revision" compose up -d --no-build "${stable_services[@]}" >>"$LOG_FILE" 2>&1
|
|
|
|
for attempt in $(seq 1 30); do
|
|
if curl -fsS --max-time 5 https://assistant.cin.su/healthz >/dev/null 2>&1; then break; fi
|
|
[[ "$attempt" == 30 ]] && fail "public health failed"
|
|
sleep 10
|
|
done
|
|
for service in "${stable_services[@]}"; do
|
|
container="assistant-${service}-1"
|
|
label="$(docker inspect "$container" --format '{{index .Config.Labels "org.opencontainers.image.revision"}}' 2>/dev/null || true)"
|
|
[[ "$label" == "$revision" ]] || fail "artifact drift container=$container"
|
|
done
|
|
log "OK stable revision=$revision"
|