mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 07:19:41 +01:00
* fix(hardcoded): give every duplicated constant one home A sweep of all 44 repos' default branches for literals that duplicate an existing source of truth. Loki's share, in four groups. WRONG, and live on the public footer. src/config/fleet-site-copy.ts still called the Zürich clinic "VitaReBa", a name retired on 2026-09-10 — its own title says "Vita · Metabolische Psychiatrie & Systemische Longevity". The generated fleet-sites.ts carried it onto loki.orangecat.ch, where it was serving until this commit. Fixed at the copy file, which is the one place that owns a site's own words, and the footer regenerated from it. WOULD HAVE WRITTEN STALE DATA. scripts/seed-fleet-site-urls.ts kept a hand-typed slug → URL map "read 2026-08-06". Two of its fifteen entries pointed at hosts retired since (aoz-wohnen.orangecat.ch, revampit.orangecat.ch), so running it would have filled empty live_url columns with addresses that only 308. It now derives the map from apps.conf — the same register the footer is generated from — which also fixes the six live sites the hand list never had. Verified: 19 sites, zero retired hosts. THE BOX ADDRESS, in seven places. scripts/hetzner/_box-env.sh has been the SSOT for it all along and sixteen scripts source it; four did not, and the shared deploy workflow — reused by ~20 repos — had the IP inline twice, so moving the box meant twenty edits. The workflow now reads the org-level Actions variable HETZNER_IP and fails loudly if it is unset, rather than ssh-ing to an empty string. loki's own deploy.yml had `vars.HETZNER_IP || '<literal>'`, a fallback that guaranteed the variable was never needed and so never noticed if wrong. ONE LAPTOP, baked into shipped code. site-cd-local.ts listed /home/g/.ssh and /home/ubuntu/.ssh as deploy-key candidates beside os.homedir() — which already IS those paths, since loki-app runs as `ubuntu` and a laptop runs as its owner; both spelled one homedir for one named person. install-push-deploy.sh wired hooks to /home/g/dev/loki, link-prod-runtime.ts to /home/g/dev/bitbaum, and scripts/fleet printed an install line only true on one machine: all now DEV_ROOT or the script's own resolved path. The two scripts in scripts/local are INSTALLED BY COPY into ~/.local/bin and run there by systemd timers, so they resolve _box-env.sh beside the real file first, then under DEV_ROOT, and exit loudly if neither exists — a security check that cannot find its target must not look like one that found nothing. Deliberately unchanged: the slug alias map (the mechanism that makes a rename safe), an executed migration's data row, the retired-handle detector's own handle list, and test fixtures reproducing past incidents. Verified: fleet-sites-derived in sync (14 sites), bash -n on every edited script, and the branch's only remaining literals are in scripts/test fixtures. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(push-deploy): the generated hook must not bake one laptop's path install-push-deploy.sh writes the hook body through an UNQUOTED heredoc, so $HERE expanded at generation time and the absolute path of one machine was committed into every repo's .husky/pre-push. kivvi and botsmann both carried it; anyone cloning those repos got a hook pointing into a stranger's home directory, and re-running the installer would have put it straight back after those repos were cleaned. The hook now resolves ${DEV_ROOT:-$HOME/dev}/loki/... at RUN time, so the generator stops re-introducing what the cleanup just removed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
93 lines
3.4 KiB
Bash
Executable File
93 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Make `git push` deploy — push-to-deploy on our own box.
|
|
#
|
|
# Installs a pre-push hook into every repo in apps.conf (plus loki
|
|
# itself) that backgrounds the existing deploy pipeline (build standalone →
|
|
# rsync → restart → health check). The hook detaches and waits a few seconds
|
|
# so the actual push isn't slowed; the deploy builds the working tree you
|
|
# just pushed from. Logs land in /tmp/push-deploy-<app>.log.
|
|
#
|
|
# Idempotent: re-running updates the hook block in place (markers).
|
|
# Husky repos get the line in .husky/pre-push; plain repos in .git/hooks.
|
|
#
|
|
# Usage: install-push-deploy.sh [app ...] (no args = all + loki)
|
|
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
|
|
|
MARK_BEGIN="# >>> loki push-deploy >>>"
|
|
MARK_END="# <<< loki push-deploy <<<"
|
|
|
|
install_hook() { # repo_path deploy_cmd app_name
|
|
local repo="$1" deploy_cmd="$2" app="$3"
|
|
local hook
|
|
if [ -d "$repo/.husky" ]; then
|
|
hook="$repo/.husky/pre-push"
|
|
[ -f "$hook" ] || { echo "#!/usr/bin/env sh" > "$hook"; chmod +x "$hook"; }
|
|
else
|
|
[ -d "$repo/.git" ] || { echo "skip $app: no .git in $repo"; return; }
|
|
hook="$repo/.git/hooks/pre-push"
|
|
[ -f "$hook" ] || { echo "#!/usr/bin/env sh" > "$hook"; chmod +x "$hook"; }
|
|
fi
|
|
|
|
# Replace any previous block, then append the current one.
|
|
local tmp
|
|
tmp=$(mktemp)
|
|
awk -v b="$MARK_BEGIN" -v e="$MARK_END" '
|
|
$0 == b { skip = 1; next }
|
|
$0 == e { skip = 0; next }
|
|
!skip { print }
|
|
' "$hook" > "$tmp" && mv "$tmp" "$hook"
|
|
|
|
cat >> "$hook" <<EOF
|
|
$MARK_BEGIN
|
|
# Pushing the repo's default branch deploys to the Hetzner box
|
|
# (background; see /tmp/push-deploy-$app.log). Repos differ: some use
|
|
# 'main', some still use 'master' — match either so push-to-deploy fires
|
|
# regardless of the repo's branch convention.
|
|
# CI GATE: the background deploy first waits for GitHub CI on the pushed
|
|
# commit and is BLOCKED on a red — prod only receives what CI verified
|
|
# (ci-gate.sh; repos without CI pass after a short grace window).
|
|
if git symbolic-ref --short HEAD 2>/dev/null | grep -qxE 'main|master'; then
|
|
( sleep 5
|
|
_sha=\$(git rev-parse HEAD)
|
|
_nwo=\$(git remote get-url origin 2>/dev/null | sed -E 's#(git@github.com:|https://github.com/)##; s#\\.git\$##')
|
|
if [ -n "\$_nwo" ] && ! bash "\${DEV_ROOT:-\$HOME/dev}/loki/scripts/hetzner/ci-gate.sh" "\$_nwo" "\$_sha"; then
|
|
echo "[push-deploy] $app: BLOCKED by CI gate for \${_sha} — fix CI, then re-push or deploy manually"
|
|
else
|
|
$deploy_cmd
|
|
fi
|
|
) >> /tmp/push-deploy-$app.log 2>&1 & disown 2>/dev/null || true
|
|
echo "[push-deploy] $app: CI-gated deploy started in background → /tmp/push-deploy-$app.log"
|
|
fi
|
|
$MARK_END
|
|
EOF
|
|
chmod +x "$hook"
|
|
echo "installed: $app ($hook)"
|
|
}
|
|
|
|
apps=("$@")
|
|
if [ ${#apps[@]} -eq 0 ]; then
|
|
mapfile -t apps < <(app_names)
|
|
apps+=(loki evig)
|
|
fi
|
|
|
|
for app in "${apps[@]}"; do
|
|
# DEV_ROOT comes from _box-env.sh (via lib.sh, sourced above) — the checkout
|
|
# root is one constant, not a laptop path repeated per special case.
|
|
if [ "$app" = "loki" ]; then
|
|
install_hook "$DEV_ROOT/loki" \
|
|
"env -u CI bash $DEV_ROOT/loki/scripts/deploy-hetzner.sh" \
|
|
loki
|
|
continue
|
|
fi
|
|
if [ "$app" = "evig" ]; then
|
|
install_hook "$DEV_ROOT/evig" \
|
|
"env -u CI bash $DEV_ROOT/evig/scripts/selfhost-deploy-evig.sh" \
|
|
evig
|
|
continue
|
|
fi
|
|
app_lookup "$app" || continue
|
|
install_hook "$REPO" \
|
|
"env -u CI bash \"\${DEV_ROOT:-\$HOME/dev}/loki/scripts/hetzner/deploy.sh\" $NAME" \
|
|
"$NAME"
|
|
done
|