From 942a0096ba131e61d5f866b7f989553bc15f44d3 Mon Sep 17 00:00:00 2001 From: Knowit Date: Sun, 3 May 2026 01:44:30 +0800 Subject: [PATCH] Add deploy/pull.sh and run it from cron for auto-deploy Cron on the host runs deploy/pull.sh every minute. It fetches main, fast-forwards the working tree, and restarts the facere-web container when deploy/nginx.conf changes (Docker bind-mounts the file by inode, so the in-container view is otherwise stale after a git reset). Co-Authored-By: Claude Opus 4.7 (1M context) --- deploy/pull.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 deploy/pull.sh diff --git a/deploy/pull.sh b/deploy/pull.sh new file mode 100755 index 0000000..2b50090 --- /dev/null +++ b/deploy/pull.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail +cd /home/ubuntu/repo/facere-website +before=$(git rev-parse HEAD) +git fetch --quiet origin main +after=$(git rev-parse origin/main) +if [ "$before" = "$after" ]; then + exit 0 +fi + +# Detect whether the bind-mounted nginx.conf changed in this update. +# Docker bind-mounts the file by inode, so a `git reset` (which replaces +# the file) requires a container restart for the new config to take effect. +nginx_changed=0 +if git diff --name-only "$before" "$after" | grep -qx 'deploy/nginx.conf'; then + nginx_changed=1 +fi + +git reset --hard origin/main +echo "[$(date -Is)] deployed $before -> $after" + +if [ "$nginx_changed" = "1" ]; then + sudo -n docker restart facere-web >/dev/null + echo "[$(date -Is)] restarted facere-web (nginx.conf changed)" +fi