38 lines
1.4 KiB
Bash
38 lines
1.4 KiB
Bash
#!/bin/bash
|
|
# ─── Gitea Post-Receive Hook ────────────────────────────────────────────────
|
|
# Location: /home/ubuntu/gitea/gitea/git/repositories/silvioalzate/cirux.git/hooks/post-receive
|
|
# Owner: ubuntu (run as gitea service user)
|
|
# Make executable: chmod +x post-receive
|
|
|
|
set -e
|
|
|
|
APP_DIR="/home/ubuntu/cirux"
|
|
LOG_FILE="/var/log/cirux-deploy.log"
|
|
BRANCH="main"
|
|
DEPLOY_SCRIPT="/home/ubuntu/cirux/deploy-auto.sh"
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Push received, starting deploy..." >> "$LOG_FILE"
|
|
|
|
# Read refs from stdin (standard git hook input)
|
|
while read oldrev newrev refname; do
|
|
# Only deploy on main branch pushes
|
|
if [ "$refname" = "refs/heads/$BRANCH" ]; then
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Deploying branch: $BRANCH" >> "$LOG_FILE"
|
|
|
|
cd "$APP_DIR"
|
|
|
|
# Run deploy script
|
|
/home/ubuntu/cirux/deploy-auto.sh >> "$LOG_FILE" 2>&1
|
|
|
|
# Verify health
|
|
sleep 5
|
|
if curl -sf http://localhost:3020/api/health > /dev/null 2>&1; then
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Deploy successful ✅" >> "$LOG_FILE"
|
|
else
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Health check failed ⚠️" >> "$LOG_FILE"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - Hook finished" >> "$LOG_FILE"
|