57 lines
1.5 KiB
Bash
Executable File
57 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Post-receive hook for dev.coppertone.tech
|
|
# Triggered when code is pushed to this bare repo
|
|
#
|
|
|
|
set -e
|
|
|
|
DOMAIN="dev.coppertone.tech"
|
|
BRANCH="main"
|
|
BARE_REPO="/docker/web-hosts/git/dev.coppertone.tech.git"
|
|
DEPLOY_DIR="/docker/web-hosts/domains/dev.coppertone.tech"
|
|
REPO_DIR="$DEPLOY_DIR/repo"
|
|
LOG_FILE="/docker/web-hosts/logs/dev.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..."
|
|
|
|
# Update working copy from bare repo
|
|
cd "$REPO_DIR"
|
|
|
|
# Fetch from bare repo (local remote)
|
|
git fetch local "$BRANCH" 2>/dev/null || git fetch origin "$BRANCH"
|
|
git checkout "$BRANCH" 2>/dev/null || git checkout -b "$BRANCH"
|
|
|
|
# Reset to the bare repo's version
|
|
git reset --hard "local/$BRANCH" 2>/dev/null || git reset --hard "origin/$BRANCH"
|
|
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 ==="
|