Author SHA1 Message Date
Bot 9ec1b1811b feat(stack-deploy): accept -e/--emergency and -f/--force flags, pass through to git-guard.sh
Flags may appear before or after the stack name (stack-deploy.sh traefik -e
and stack-deploy.sh -e traefik both work) — the stack name is whatever
argument isn't a recognized flag. No change to the render/mount-guard/deploy
logic; this only changes how the git-guard.sh pre-flight is invoked. See
deploy/git-guard.sh header for what each flag actually does.
2026-09-12 00:04:42 -07:00
Bot 8fa085ebde feat(git-guard): add -e/--emergency (try alternate Gitea hosts) and -f/--force (skip sync check)
Adds two opt-in flags to break the circular dependency discovered during
the 2026-09-12 traefik/keepalived incident: Traefik down -> VIP/hostname
unreachable -> git-guard can't fetch -> stack-deploy.sh traefik blocked ->
can't redeploy traefik to fix Traefik.

-e/--emergency: probes git.bryanmail.net, then the VIP (192.168.4.30), then
each node's direct IP (.31/.32/.33) on Gitea's direct ingress port 3000
(bypasses Traefik/VIP entirely), switches origin to the first reachable one,
then runs the NORMAL sync logic against it (behind/ahead/diverged handling
unchanged — this only changes which host is used, never skips the safety
checks). Prints a reminder to restore the real origin URL afterward; never
persists the swap anywhere.

-f/--force: skips the sync check entirely, for the genuine last-resort case
where Gitea itself (not just routing) is unreachable. Loud warning banner.

Verified git ls-remote succeeds unauthenticated over plain http against
each candidate before writing this, so no credential-smuggling concern.
2026-09-12 00:03:59 -07:00
Bot 5ab1ae1e8b chore(traefik): re-trigger provision-secrets — traefik.env was found missing on disk post-migration
ci/woodpecker/push/deploy Pipeline was successful
traefik/traefik.env did not exist on the host after PR #21 merged. Root
cause: provisioning only renders on a push touching traefik/, and traefik
is bootstrap-tier (stack-deploy.sh runs manually, never via the pipeline).
A manual stack-deploy.sh traefik run apparently happened while the env file
was absent, causing Swarm's own interpolation to render
KEEPALIVED_PASSWORD/KEEPALIVED_VIRTUAL_IPS as empty strings on
keepalived-master. This comment-only change re-triggers provision-secrets;
a manual stack-deploy.sh traefik run is still required afterward to apply
the freshly-rendered env to the running services.
2026-09-11 23:17:13 -07:00
3 changed files with 154 additions and 2 deletions
+113
View File
@@ -23,18 +23,131 @@
# remote both moved) backup/stash/reset recovery steps and exits.
#
# Exit codes: 0 = safe to deploy, 1 = blocked, needs human intervention
#
# ── Flags (added 2026-09-12, circular-dependency bootstrap incident) ────────
#
# -e, --emergency
# Before the normal fetch, tries each candidate Gitea endpoint in order
# (git.bryanmail.net -> 192.168.4.30 VIP -> .31 -> .32 -> .33 node IPs,
# each over plain http on port 3000, which is Gitea's direct ingress
# port — bypasses Traefik/VIP entirely) and switches `origin` to the
# first one that responds to `git ls-remote` within a short timeout.
# This solves the bootstrap circular dependency where Traefik is down,
# so HTTPS access to git.bryanmail.net is unreachable, so git-guard
# can't fetch, so stack-deploy.sh can't redeploy traefik to fix itself.
# Once a reachable endpoint is found, NORMAL sync logic still runs
# (behind/ahead/diverged handling is unchanged) — this flag only changes
# *which host* is used, never skips the safety checks themselves.
# Prints a loud reminder to restore the real origin URL afterward; never
# commits the swapped URL anywhere.
#
# -f, --force
# Skips the sync check ENTIRELY — no fetch, no comparison, no commit/push
# offer. Deploys whatever is on disk right now, as-is. This is the last
# resort for a genuine emergency where NONE of the candidate hosts in
# --emergency are reachable (e.g. Gitea itself is down, not just
# routing). Prints a loud warning banner. Never use this for routine
# work — it defeats the entire purpose of this script and is the exact
# failure mode (deploying a stale/unreviewed tree) git-guard exists to
# prevent.
#
# Both flags are passed through from stack-deploy.sh's own -e/-f flags;
# see that script's header for the calling convention.
# ─────────────────────────────────────────────────────────────────────────
set -euo pipefail
DIR="/volume1/docker/compose-files"
cd "$DIR"
# ---- Flag parsing ----
EMERGENCY=0
FORCE=0
for arg in "$@"; do
case "$arg" in
-e|--emergency) EMERGENCY=1 ;;
-f|--force) FORCE=1 ;;
esac
done
# ---- Force mode: skip everything ----
if [ "$FORCE" -eq 1 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!! FORCE MODE (-f/--force): git-guard sync check SKIPPED ENTIRELY."
echo "!! Deploying whatever is on disk right now, as-is. No fetch, no"
echo "!! comparison with origin/main was performed. This is a LAST RESORT"
echo "!! for emergencies where origin is completely unreachable — verify"
echo "!! independently that the local tree is what you intend to deploy."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 0
fi
# Non-interactive detection (Woodpecker/cron have no TTY on stdin)
INTERACTIVE=0
[ -t 0 ] && INTERACTIVE=1
echo "==> git-guard: checking repo sync state"
# ---- Emergency mode: find a reachable Gitea endpoint before fetching ----
# Candidate order: public hostname (normal path) -> VIP -> each node's direct
# IP. Each is tried over plain http on port 3000 (Gitea's direct ingress
# port, published outside Traefik — see traefik/traefik.yaml git service
# port mapping), since the whole point is to bypass Traefik/VIP when THOSE
# are what's broken. A short `git ls-remote` timeout keeps an unreachable
# candidate from stalling the whole check for long.
if [ "$EMERGENCY" -eq 1 ]; then
echo "!! EMERGENCY MODE (-e/--emergency): probing candidate Gitea endpoints"
echo "!! (bypassing the normal https://git.bryanmail.net path if needed)..."
ORIGINAL_URL="$(git remote get-url origin)"
CANDIDATES=(
"https://git.bryanmail.net/homelab/compose-files.git"
"http://192.168.4.30:3000/homelab/compose-files.git"
"http://192.168.4.31:3000/homelab/compose-files.git"
"http://192.168.4.32:3000/homelab/compose-files.git"
"http://192.168.4.33:3000/homelab/compose-files.git"
)
FOUND=""
for candidate in "${CANDIDATES[@]}"; do
echo -n " trying $candidate ... "
if timeout 5 git ls-remote "$candidate" HEAD >/dev/null 2>&1; then
echo "OK"
FOUND="$candidate"
break
else
echo "unreachable"
fi
done
if [ -z "$FOUND" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!! EMERGENCY MODE: none of the candidate endpoints responded."
echo "!! Gitea itself may be down (not just routing) — this is beyond what"
echo "!! an alternate host path can fix. Options:"
echo "!! A) Diagnose Gitea directly: check the git_gitea-server service"
echo "!! and container on docker-1."
echo "!! B) If you are certain the on-disk tree is correct and Gitea is"
echo "!! genuinely unreachable, re-run with -f/--force instead — but"
echo "!! read that flag's warning carefully first."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 1
fi
if [ "$FOUND" != "$ORIGINAL_URL" ]; then
git remote set-url origin "$FOUND"
echo "==> origin temporarily switched to: $FOUND"
echo "!! REMINDER: once the normal path (git.bryanmail.net / Traefik) is"
echo "!! confirmed healthy again, restore the real origin URL:"
echo "!! cd $DIR && git remote set-url origin \"$ORIGINAL_URL\""
echo "!! This swap is never committed anywhere and only affects this"
echo "!! local checkout's git config."
else
echo "==> Normal origin URL ($FOUND) is reachable — no swap needed."
fi
echo
fi
git fetch origin --quiet
LOCAL="$(git rev-parse main)"
+28 -2
View File
@@ -38,10 +38,36 @@
# pre-escaping) or values get doubled twice. Getting this wrong
# silently corrupts any secret/hash containing '$' (confirmed impact:
# LITELLM keys truncated, IMMICH_KIOSK_BASICAUTH bcrypt hash mismatched).
#
# Usage: stack-deploy.sh [-e|--emergency] [-f|--force] <stack-name>
# Flags may appear before or after the stack name, e.g. both
# `stack-deploy.sh traefik -e` and `stack-deploy.sh -e traefik` work.
#
# -e/--emergency and -f/--force (added 2026-09-12, circular-dependency
# bootstrap incident — see deploy/git-guard.sh header for full detail):
# Both are passed straight through to git-guard.sh unchanged; this script
# does not interpret them itself beyond stripping them from the stack-name
# argument list. -e tries alternate Gitea endpoints (VIP, then each node's
# direct IP) before falling back to normal sync logic against whichever
# one responds. -f skips the sync check entirely — last resort only, read
# the warning banner it prints. Neither flag changes anything about the
# render/mount-guard/deploy steps below; they only affect whether and how
# git-guard.sh's pre-flight check runs.
set -euo pipefail
STACK="${1:?Usage: stack-deploy.sh <stack-name>}"
# ── Flag parsing (stack name is whatever's left after flags are stripped) ──
GUARD_FLAGS=()
STACK=""
for arg in "$@"; do
case "$arg" in
-e|--emergency) GUARD_FLAGS+=(-e) ;;
-f|--force) GUARD_FLAGS+=(-f) ;;
*) STACK="$arg" ;;
esac
done
: "${STACK:?Usage: stack-deploy.sh [-e|--emergency] [-f|--force] <stack-name>}"
DIR="/volume1/docker/compose-files"
PY="$DIR/deploy/envparse.py"
MOUNT_GUARD="$DIR/deploy/mount-guard.py"
@@ -50,7 +76,7 @@ GLOBAL_ENV="$DIR/deploy/global.env"
# ── Pre-flight: ensure local checkout is in sync with Gitea ─────────────────
# Prevents deploying from a stale/diverged local tree (see incident 2026-08-26).
# Invoked via `bash` explicitly so the tracked file's exec bit doesn't matter.
bash "$DIR/deploy/git-guard.sh" || { echo "ERROR: git-guard check failed. Deploy aborted."; exit 1; }
bash "$DIR/deploy/git-guard.sh" "${GUARD_FLAGS[@]:-}" || { echo "ERROR: git-guard check failed. Deploy aborted."; exit 1; }
# ── Locate compose file(s) ──────────────────────────────────────────────────
+13
View File
@@ -30,6 +30,19 @@
# keepalived itself. Set TRAEFIK_KEEPALIVED_PASSWORD in Woodpecker to a
# value 8 characters or fewer (or accept that only the first 8 chars are
# actually significant) so the effective negotiated value is unambiguous.
#
# 2026-09-12 RE-TRIGGER: traefik.env was found MISSING on disk after the
# Pattern C migration merged — the manifest-driven provisioning render only
# happens on a push that changes traefik/, and traefik is bootstrap-tier
# (stack-deploy.sh must be run manually; the pipeline never auto-deploys
# this stack). A manual `stack-deploy.sh traefik` had apparently been run
# while traefik.env was absent, causing Swarm's own interpolation to
# silently render KEEPALIVED_PASSWORD/KEEPALIVED_VIRTUAL_IPS as EMPTY
# STRINGS on keepalived-master (not missing — empty, which is worse,
# since it's a valid-looking VRRP auth string that mismatches everything).
# This comment-only change re-triggers provision-secrets to re-render and
# re-ship traefik.env; a manual `stack-deploy.sh traefik` must still be run
# afterward to actually apply it to the running services.
# ─────────────────────────────────────────────────────────────────────────
# ── Keepalived (non-secret config) ────────────────────────────────────────