Files
rx.scoreodonto.com/deploy-prod.sh
T
VPS 4 Deploy Agent 610c183b35
continuous-integration/webhook Deploy concluído (VPS4)
feat(deploy): add GitOps automation - listener 9003, update-version.js, deploy-prod.sh GitOps
2026-05-30 15:32:11 +02:00

67 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# ─── deploy-prod.sh (rx.scoreodonto.com) ──────────────────────────────────────
# GitOps: VPS4 (Builder) → VPS1 (Produção)
# Modelo B: rsync do código-fonte → docker compose build na VPS1
# ──────────────────────────────────────────────────────────────────────────────
set -e
PROD_VPS="10.99.0.1"
PROD_USER="deploy"
PROD_PATH="/home/deploy/stack/rx.scoreodonto.com"
LOG_FILE="/home/deploy/stack/webhook-listener/deploy.log"
LOG_TAG="[rx.scoreodonto.com]"
DOCKER_HOST_REMOTE="unix:///run/user/1000/docker.sock"
LOCK_FILE="/tmp/deploy-rx-scoreodonto.lock"
if [ -f "$LOCK_FILE" ]; then
echo "🚨 Deploy já em andamento!" | tee -a "$LOG_FILE"
exit 1
fi
touch "$LOCK_FILE"
trap 'rm -f "$LOCK_FILE"' EXIT
log() { echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] ${LOG_TAG} $1" | tee -a "$LOG_FILE"; }
log "🚀 Iniciando deploy..."
# 1. GitOps: fonte de verdade é o Gitea (VPS3)
cd "$PROD_PATH"
log "📦 git fetch + reset --hard origin/main"
git fetch origin main
git reset --hard origin/main
# 2. Bump de versão (sincroniza version.txt → package.json + index.html)
log "🔢 Incrementando versão..."
node update-version.js
# 3. Enviar código-fonte para VPS1
log "🚚 rsync código-fonte → VPS1..."
rsync -avz --delete \
--exclude '.git' \
--exclude '.env' \
--exclude 'node_modules' \
--exclude 'uploads' \
--exclude 'processed' \
--exclude 'data' \
--exclude 'dental-server/updates' \
"$PROD_PATH/" \
"${PROD_USER}@${PROD_VPS}:${PROD_PATH}/"
# 4. Build + swap do container na VPS1 (sem downtime)
log "🐳 docker compose build + up na VPS1..."
ssh -o BatchMode=yes -o StrictHostKeyChecking=no "${PROD_USER}@${PROD_VPS}" "
set -e
cd ${PROD_PATH}
export DOCKER_HOST=${DOCKER_HOST_REMOTE}
docker compose build app
docker compose up -d --no-deps app
"
# 5. Commit do bump de versão de volta ao Gitea (listener ignora → sem loop)
log "💾 git commit + push do bump de versão..."
git add dental-server/version.txt dental-server/package.json dental-server/public/index.html
git commit -m "chore(deploy): bump version" || true
git push origin main || true
log "✅ Deploy concluído sem downtime!"