- Forward X-Site-Host from Astro to the bridge so loopback calls use the public domain JSON - Normalize newsproject.bitreport.pt.json (categories slug/label, wp on 127.0.0.1:8080) - Degrade homepage/trending when WordPress is down instead of 500 - Extend webhook-deploy.sh for config/ and wordpress/ changes; add deploy-hook-server + systemd unit - Document automatic Gitea webhook flow in docs/deployment.md; align DOMAINS_CONFIG_PATH env Co-Authored-By: Paperclip <[email protected]> Made-with: Cursor
83 lines
2.4 KiB
Bash
Executable File
83 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Lightweight Gitea webhook handler — triggered by POST from Gitea on push to main.
|
|
# Deploy: run this as a cron, or via a minimal webhook receiver (e.g. adnanh/webhook).
|
|
# Example crontab (pulls and redeploys every 5 min if new commits):
|
|
# */5 * * * * /opt/news-platform/deploy/scripts/webhook-deploy.sh >> /var/log/news-deploy.log 2>&1
|
|
set -euo pipefail
|
|
|
|
APP_DIR="/opt/news-platform"
|
|
LOCK_FILE="/tmp/news-platform-deploy.lock"
|
|
LOG_TAG="webhook-deploy"
|
|
|
|
log() { echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [$LOG_TAG] $*"; }
|
|
|
|
# Prevent concurrent deploys
|
|
if [ -f "$LOCK_FILE" ]; then
|
|
log "Deploy already in progress, skipping."
|
|
exit 0
|
|
fi
|
|
touch "$LOCK_FILE"
|
|
trap 'rm -f "$LOCK_FILE"' EXIT
|
|
|
|
# Fetch remote state
|
|
cd "$APP_DIR"
|
|
git fetch origin main --quiet
|
|
|
|
LOCAL=$(git rev-parse HEAD)
|
|
REMOTE=$(git rev-parse origin/main)
|
|
|
|
if [ "$LOCAL" = "$REMOTE" ]; then
|
|
log "Already up-to-date ($LOCAL), nothing to deploy."
|
|
exit 0
|
|
fi
|
|
|
|
log "New commit detected: $LOCAL → $REMOTE. Starting deploy..."
|
|
|
|
git reset --hard origin/main
|
|
|
|
# Rebuild bridge if changed
|
|
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^bridge/"; then
|
|
log "Bridge changed — rebuilding..."
|
|
cd "$APP_DIR/bridge"
|
|
npm ci --silent
|
|
npm run build
|
|
systemctl restart news-bridge
|
|
log "Bridge restarted."
|
|
fi
|
|
|
|
# Rebuild frontend if changed
|
|
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^frontend/"; then
|
|
log "Frontend changed — rebuilding..."
|
|
cd "$APP_DIR/frontend"
|
|
npm ci --silent
|
|
npm run build
|
|
systemctl restart news-frontend
|
|
log "Frontend restarted."
|
|
fi
|
|
|
|
# Reload nginx if config changed
|
|
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^deploy/nginx/"; then
|
|
log "Nginx config changed — reloading..."
|
|
cp "$APP_DIR/deploy/nginx/newsproject.bitreport.pt.conf" \
|
|
/etc/nginx/sites-available/newsproject.bitreport.pt.conf
|
|
nginx -t && systemctl reload nginx
|
|
log "Nginx reloaded."
|
|
fi
|
|
|
|
# Domain JSON is cached in the bridge process — restart when config changes
|
|
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^config/"; then
|
|
log "Domain config changed — restarting bridge + frontend..."
|
|
systemctl restart news-bridge
|
|
systemctl restart news-frontend
|
|
fi
|
|
|
|
# WordPress compose or plugins
|
|
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^wordpress/"; then
|
|
log "WordPress stack changed — docker compose up..."
|
|
cd "$APP_DIR/wordpress"
|
|
docker compose up -d --remove-orphans
|
|
systemctl restart news-wordpress || true
|
|
fi
|
|
|
|
log "Deploy complete at $REMOTE."
|