summaryrefslogtreecommitdiff
path: root/hooks
diff options
context:
space:
mode:
authorVoid Agent <void@jayrup.hermes>2026-07-31 16:40:20 +0100
committerVoid Agent <void@jayrup.hermes>2026-07-31 16:40:20 +0100
commit14db9e8770ee592c20332eefc0ac9e6a3c59deff (patch)
treef819767ecd2dee6b0ca07c104d3899868b926325 /hooks
parent511e2cb82ff92056ffcdaa840046a1702c93b128 (diff)
add dockerized deploy script + post-receive hook for push-to-deploy
Diffstat (limited to 'hooks')
-rwxr-xr-xhooks/post-receive44
1 files changed, 44 insertions, 0 deletions
diff --git a/hooks/post-receive b/hooks/post-receive
new file mode 100755
index 0000000..378e777
--- /dev/null
+++ b/hooks/post-receive
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+# post-receive hook for meru's homepage.git bare repo.
+# Deploys jayrup.me on every push to main, using the pushed deploy-docker.sh.
+#
+# Install on meru (one-time):
+# cp hooks/post-receive ~/projects/homepage.git/hooks/post-receive
+# chmod +x ~/projects/homepage.git/hooks/post-receive
+# Also authorize meru's SSH key on nandi (jayrup@jayrup.me ~/.ssh/authorized_keys).
+#
+# Log: /tmp/homepage-deploy.log — also echoed to the pusher (tee).
+set -uo pipefail
+
+# Serialize concurrent pushes (flock from util-linux)
+exec 9>/tmp/homepage-deploy.lock
+flock 9
+
+LOG=/tmp/homepage-deploy.log
+exec > >(tee -a "$LOG") 2>&1
+echo "=== post-receive $(date -u +%Y-%m-%dT%H:%M:%SZ) ==="
+
+BARE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
+BUILD_DIR="/tmp/homepage-build"
+rm -rf "$BUILD_DIR"
+mkdir -p "$BUILD_DIR"
+
+DEPLOYED=0
+while read oldrev newrev ref; do
+ case "$ref" in
+ refs/heads/main)
+ OLD_SHA="$(git --git-dir="$BARE_DIR" rev-parse --short "$oldrev")"
+ NEW_SHA="$(git --git-dir="$BARE_DIR" rev-parse --short "$newrev")"
+ echo ">> push to main: $OLD_SHA..$NEW_SHA"
+ # Snapshot the pushed tree (no .git, exact commit)
+ git --git-dir="$BARE_DIR" archive "$newrev" | tar -x -C "$BUILD_DIR"
+ bash "$BUILD_DIR/deploy-docker.sh" "$BUILD_DIR" "$NEW_SHA"
+ DEPLOYED=1
+ ;;
+ *)
+ echo ">> skipped $ref (only refs/heads/main deploys)"
+ ;;
+ esac
+done
+
+[ "$DEPLOYED" -eq 1 ] && echo "=== hook done OK ===" || echo "=== nothing deployed ==="