Skip to content

Commit ef60297

Browse files
brian033claude
andcommitted
deploy: add auto-deploy script for cron-based podman deploys
Polls origin/main for new commits, builds new image, and swaps container only if build succeeds. Old container stays running on build failure. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6895416 commit ef60297

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

scripts/auto-deploy.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Auto-deploy: pull from origin, rebuild if changed, swap container.
3+
# Usage:
4+
# ./scripts/auto-deploy.sh # 手動跑
5+
# */5 * * * * /path/to/auto-deploy.sh # cron 自動跑
6+
7+
set -euo pipefail
8+
9+
REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
10+
cd "$REPO_DIR"
11+
12+
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"; }
13+
14+
log "Checking for updates..."
15+
git fetch origin main
16+
17+
LOCAL=$(git rev-parse HEAD)
18+
REMOTE=$(git rev-parse origin/main)
19+
20+
log "Local: $LOCAL"
21+
log "Remote: $REMOTE"
22+
23+
if [ "$LOCAL" = "$REMOTE" ]; then
24+
log "Already up to date. Nothing to do."
25+
exit 0
26+
fi
27+
28+
log "New commits detected. Pulling..."
29+
git pull origin main
30+
log "Pull complete. HEAD is now $(git rev-parse --short HEAD)"
31+
32+
log "Building new image..."
33+
if podman-compose build; then
34+
log "Build succeeded. Stopping old container..."
35+
podman-compose down
36+
log "Starting new container..."
37+
podman-compose up -d
38+
log "Deploy complete!"
39+
else
40+
log "BUILD FAILED — old container is still running."
41+
exit 1
42+
fi

0 commit comments

Comments
 (0)