feat: auto-deploy web on git pull + deploy SHA in spec footer
heal.sh now: 1. git fetch + reset --hard origin/main when remote is ahead 2. writes web/data/deploy.json (sha + timestamp) after each pull 3. nginx reload if web/ files changed 4. falls back to writing deploy.json on first run if missing spec/index.html shows deployed commit SHA + timestamp in footer. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
be412e99bc
commit
9027718f7f
2 changed files with 52 additions and 0 deletions
37
heal.sh
Executable file
37
heal.sh
Executable file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Self-heal: pull latest git changes, deploy web content, keep containers up.
|
||||||
|
# Runs every 5 minutes via systemd timer.
|
||||||
|
set -euo pipefail
|
||||||
|
cd /opt/xetup
|
||||||
|
|
||||||
|
LOG="[heal $(date '+%H:%M:%S')]"
|
||||||
|
|
||||||
|
# Pull latest changes (ff-only: never merge, just update)
|
||||||
|
BEFORE=$(git rev-parse HEAD 2>/dev/null || echo "none")
|
||||||
|
git fetch --quiet origin main 2>/dev/null || true
|
||||||
|
REMOTE=$(git rev-parse origin/main 2>/dev/null || echo "")
|
||||||
|
|
||||||
|
if [ -n "$REMOTE" ] && [ "$BEFORE" != "$REMOTE" ]; then
|
||||||
|
git reset --hard origin/main --quiet 2>/dev/null || true
|
||||||
|
AFTER=$(git rev-parse HEAD)
|
||||||
|
echo "$LOG deployed $BEFORE → $AFTER"
|
||||||
|
|
||||||
|
# Write deployed commit info for the web (spec page footer)
|
||||||
|
echo "{\"sha\":\"$(git rev-parse --short HEAD)\",\"ts\":\"$(date -u '+%Y-%m-%dT%H:%M:%SZ')\"}" \
|
||||||
|
> web/data/deploy.json
|
||||||
|
|
||||||
|
# If web content changed, reload nginx config
|
||||||
|
if git diff --name-only "$BEFORE" "$AFTER" 2>/dev/null | grep -q '^web/'; then
|
||||||
|
echo "$LOG web/ changed - reloading nginx"
|
||||||
|
/usr/bin/docker compose exec -T web nginx -s reload 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Always keep deploy.json fresh on first run if missing
|
||||||
|
if [ ! -f web/data/deploy.json ]; then
|
||||||
|
echo "{\"sha\":\"$(git rev-parse --short HEAD)\",\"ts\":\"$(date -u '+%Y-%m-%dT%H:%M:%SZ')\"}" \
|
||||||
|
> web/data/deploy.json
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure all containers are running
|
||||||
|
/usr/bin/docker compose up -d --remove-orphans 2>&1 | grep -v "up-to-date\|unchanged" || true
|
||||||
|
|
@ -1015,6 +1015,8 @@
|
||||||
<a href="https://git.xetup.x9.cz/x9/xetup">Forgejo</a>
|
<a href="https://git.xetup.x9.cz/x9/xetup">Forgejo</a>
|
||||||
·
|
·
|
||||||
<a href="/">xetup.x9.cz</a>
|
<a href="/">xetup.x9.cz</a>
|
||||||
|
·
|
||||||
|
web: <span id="deploy-sha" style="font-family:monospace">...</span>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -1376,6 +1378,19 @@
|
||||||
})();
|
})();
|
||||||
|
|
||||||
enhanceRows();
|
enhanceRows();
|
||||||
|
|
||||||
|
// Show deployed commit in footer
|
||||||
|
fetch('/data/deploy.json')
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(d => {
|
||||||
|
const el = document.getElementById('deploy-sha');
|
||||||
|
if (el && d.sha) {
|
||||||
|
const ts = d.ts ? ' (' + new Date(d.ts).toLocaleString('cs-CZ', {day:'2-digit',month:'2-digit',hour:'2-digit',minute:'2-digit'}) + ')' : '';
|
||||||
|
el.textContent = d.sha + ts;
|
||||||
|
el.title = d.ts || '';
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue