60 lines
1.7 KiB
Bash
Executable File
60 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Post-receive hook for games.coppertone.tech
|
|
# Triggered when code is pushed to this bare repo
|
|
#
|
|
|
|
set -e
|
|
|
|
DOMAIN="games.coppertone.tech"
|
|
BRANCH="main"
|
|
BARE_REPO="/docker/web-hosts/git/games.coppertone.tech.git"
|
|
DEPLOY_DIR="/docker/web-hosts/domains/games.coppertone.tech"
|
|
REPO_DIR="$DEPLOY_DIR/repo"
|
|
LOG_FILE="/docker/web-hosts/logs/games.coppertone.tech-deploy.log"
|
|
|
|
mkdir -p "$(dirname "$LOG_FILE")"
|
|
|
|
log() {
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
log "=== Deployment triggered ==="
|
|
|
|
# Read the branch being pushed
|
|
while read oldrev newrev refname; do
|
|
pushed_branch=$(echo "$refname" | sed 's|refs/heads/||')
|
|
log "Received push to branch: $pushed_branch"
|
|
|
|
if [ "$pushed_branch" != "$BRANCH" ]; then
|
|
log "Ignoring push to $pushed_branch (watching $BRANCH)"
|
|
continue
|
|
fi
|
|
|
|
log "Deploying $BRANCH branch..."
|
|
|
|
# Unset GIT_DIR to avoid bare repo issues
|
|
unset GIT_DIR
|
|
|
|
# Update working copy from bare repo
|
|
cd "$REPO_DIR"
|
|
|
|
# Fetch from bare repo (local remote)
|
|
git fetch local "$BRANCH" 2>&1 | tee -a "$LOG_FILE" || git fetch origin "$BRANCH" 2>&1 | tee -a "$LOG_FILE"
|
|
git checkout "$BRANCH" 2>&1 | tee -a "$LOG_FILE" || git checkout -b "$BRANCH" 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
# Reset to the bare repo's version
|
|
git reset --hard "local/$BRANCH" 2>&1 | tee -a "$LOG_FILE" || git reset --hard "origin/$BRANCH" 2>&1 | tee -a "$LOG_FILE"
|
|
log "Updated to: $(git log -1 --oneline)"
|
|
|
|
# Run deploy script
|
|
if [ -x "$DEPLOY_DIR/deploy.sh" ]; then
|
|
log "Running deploy script..."
|
|
"$DEPLOY_DIR/deploy.sh" 2>&1 | tee -a "$LOG_FILE"
|
|
else
|
|
log "No deploy.sh found, skipping build"
|
|
fi
|
|
done
|
|
|
|
log "=== Deployment complete ==="
|