summaryrefslogtreecommitdiff
path: root/scripts/post-receive.sample
diff options
context:
space:
mode:
authorTyler Hoang <tyler@tylerhoang.xyz>2026-05-30 00:26:08 -0700
committerTyler Hoang <tyler@tylerhoang.xyz>2026-05-30 00:26:08 -0700
commitc0724a62c5e5742469339ec7aef4d0f509e10559 (patch)
treeb9e646b400f49a8759b5f0d5ecbab3b80e8a3387 /scripts/post-receive.sample
parent5fbc175e540803d919863f3d90dffc3c0645a90b (diff)
fix: align deploy flow with post-receive checkout (no .git in /var/www)
The working tree at /var/www/prism-v2 is populated by a post-receive hook that does `git --work-tree=... checkout -f`, so it has no .git directory. Drop git operations from deploy.sh and add scripts/post-receive.sample plus README setup for the bare repo + hook + sudoers wiring. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Diffstat (limited to 'scripts/post-receive.sample')
-rwxr-xr-xscripts/post-receive.sample32
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/post-receive.sample b/scripts/post-receive.sample
new file mode 100755
index 0000000..3ee898d
--- /dev/null
+++ b/scripts/post-receive.sample
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+# Sample git post-receive hook for /srv/git/prism-v2.git on the VPS.
+#
+# Install:
+# sudo cp /var/www/prism-v2/scripts/post-receive.sample /srv/git/prism-v2.git/hooks/post-receive
+# sudo chmod +x /srv/git/prism-v2.git/hooks/post-receive
+#
+# Required sudoers entry so the git user can restart services without a password.
+# Adjust GIT_USER if your git is owned by a different account.
+# GIT_USER ALL=(root) NOPASSWD: /var/www/prism-v2/scripts/deploy.sh
+
+set -euo pipefail
+
+BRANCH="master"
+WEB_DIR="/var/www/prism-v2"
+GIT_DIR="/srv/git/prism-v2.git"
+LOG="/var/log/git-deploy.log"
+
+exec >> "$LOG" 2>&1
+
+while read -r oldrev newrev refname; do
+ if [ "$refname" = "refs/heads/$BRANCH" ]; then
+ echo "$(date -Is): Checking out $BRANCH to $WEB_DIR"
+ sudo -u www-data git --work-tree="$WEB_DIR" --git-dir="$GIT_DIR" checkout -f "$BRANCH"
+
+ echo "$(date -Is): Running deploy.sh"
+ sudo "$WEB_DIR/scripts/deploy.sh"
+
+ echo "$(date -Is): Done."
+ fi
+done