57 lines
1.6 KiB
Bash
Executable File
57 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Post-receive hook for coppertone.tech deployment
|
|
# Deploys when the main branch is pushed
|
|
|
|
set -e
|
|
|
|
BRANCH="main"
|
|
DEPLOY_DIR="/docker/web-hosts/domains/coppertone.tech"
|
|
REPO_DIR="/docker/web-hosts/git/coppertone.tech.git"
|
|
LOG_FILE="/docker/web-hosts/logs/coppertone.tech-deploy.log"
|
|
|
|
mkdir -p "$(dirname "$LOG_FILE")"
|
|
|
|
should_deploy=false
|
|
while read -r oldrev newrev refname; do
|
|
branch="${refname#refs/heads/}"
|
|
if [ "$branch" = "$BRANCH" ]; then
|
|
should_deploy=true
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ "$should_deploy" != true ]; then
|
|
echo "No $BRANCH update detected; skipping deploy" | tee -a "$LOG_FILE"
|
|
exit 0
|
|
fi
|
|
|
|
echo "=== Deployment started at $(date) (branch: $BRANCH) ===" | tee -a "$LOG_FILE"
|
|
|
|
# Create deploy directory if it doesn't exist
|
|
mkdir -p "$DEPLOY_DIR"
|
|
|
|
# Checkout the latest code from bare repo
|
|
echo "Checking out latest code..." | tee -a "$LOG_FILE"
|
|
GIT_WORK_TREE="$DEPLOY_DIR" GIT_DIR="$REPO_DIR" git checkout -f "$BRANCH" 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
cd "$DEPLOY_DIR"
|
|
|
|
# Build new containers
|
|
echo "Building containers..." | tee -a "$LOG_FILE"
|
|
podman-compose -f podman-compose.yml build 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
# Stop old containers
|
|
echo "Stopping old containers..." | tee -a "$LOG_FILE"
|
|
podman-compose -f podman-compose.yml down 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
# Start new containers
|
|
echo "Starting new containers..." | tee -a "$LOG_FILE"
|
|
podman-compose -f podman-compose.yml up -d 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
# Reload nginx
|
|
echo "Reloading nginx..." | tee -a "$LOG_FILE"
|
|
/docker/www/scripts/nginx-reload.sh 2>&1 | tee -a "$LOG_FILE"
|
|
|
|
echo "=== Deployment completed at $(date) ===" | tee -a "$LOG_FILE"
|