chore(ops): migrate clube67 to newwhats.clube67.com directory
continuous-integration/webhook Falha no deploy de clube67_newwhats.local (VPS 4)
continuous-integration/webhook Falha no deploy de clube67_newwhats.local (VPS 4)
This commit is contained in:
Executable
+86
@@ -0,0 +1,86 @@
|
||||
# ─── deploy-prod-builder.sh ──────────────────────────────────────────────────
|
||||
# Script sênior de automação de build e despacho (GitOps) de VPS 4 -> VPS 1.
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
set -e
|
||||
|
||||
LOCK_FILE="/tmp/deploy-prod.lock"
|
||||
if [ -f "$LOCK_FILE" ]; then
|
||||
echo "🚨 Deploy já está em andamento! Aguarde..."
|
||||
exit 1
|
||||
fi
|
||||
touch "$LOCK_FILE"
|
||||
|
||||
# Garante que o lock file será apagado no final do script mesmo se houver erro
|
||||
trap 'rm -f "$LOCK_FILE"' EXIT
|
||||
|
||||
LOG_FILE="/home/deploy/stack/webhook-listener/deploy.log"
|
||||
|
||||
log() {
|
||||
echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
log "🚀 Iniciando ciclo de build e deploy automático..."
|
||||
|
||||
# 1. Atualizar repositório Git
|
||||
log "📦 Sincronizando repositório Git local na VPS 4..."
|
||||
cd /home/deploy/stack/newwhats.clube67.com/newwhats.local
|
||||
git fetch origin main
|
||||
git reset --hard origin/main
|
||||
|
||||
# 1.1 Incrementar versão e histórico de deploys
|
||||
log "🔢 Incrementando versão e registrando histórico de deploy..."
|
||||
cd /home/deploy/stack/newwhats.clube67.com/newwhats.local
|
||||
node update-version.js
|
||||
|
||||
# 2. Compilar o Backend
|
||||
log "⚙️ Instalando dependências e compilando o Backend..."
|
||||
cd /home/deploy/stack/newwhats.clube67.com/newwhats.local/backend
|
||||
npm install
|
||||
npm run build
|
||||
npx prisma generate
|
||||
|
||||
# 2.1 Compilar os Plugins
|
||||
log "⚙️ Compilando os Plugins da plataforma..."
|
||||
/home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/node_modules/.bin/tsc -p /home/deploy/stack/newwhats.clube67.com/newwhats.local/plugins/tsconfig.json || true
|
||||
|
||||
|
||||
# 3. Compilar o Frontend
|
||||
log "⚙️ Instalando dependências e compilando o Frontend (Next.js)..."
|
||||
cd /home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend
|
||||
npm install
|
||||
NEXT_PUBLIC_API_URL=https://clube67.com npm run build
|
||||
|
||||
# 4. Sincronizar arquivos compilados com a VPS 1 (Produção) via Rsync VPN
|
||||
log "🚚 Despachando Backend compilado para a VPS 1 (Produção)..."
|
||||
rsync -avz --delete --exclude '.env' /home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/dist/ deploy@10.99.0.1:/home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/dist/
|
||||
|
||||
rsync -avz --delete /home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/node_modules/ deploy@10.99.0.1:/home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/node_modules/
|
||||
|
||||
rsync -avz --delete /home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/prisma/ deploy@10.99.0.1:/home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/prisma/
|
||||
|
||||
rsync -avz /home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/package.json /home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/package-lock.json deploy@10.99.0.1:/home/deploy/stack/newwhats.clube67.com/newwhats.local/backend/
|
||||
|
||||
log "🚚 Despachando Frontend compilado para a VPS 1 (Produção)..."
|
||||
rsync -avz --delete /home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/.next/ deploy@10.99.0.1:/home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/.next/
|
||||
|
||||
rsync -avz --delete /home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/node_modules/ deploy@10.99.0.1:/home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/node_modules/
|
||||
|
||||
rsync -avz --delete /home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/public/ deploy@10.99.0.1:/home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/public/
|
||||
|
||||
rsync -avz /home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/next.config.mjs /home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/package.json /home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/package-lock.json deploy@10.99.0.1:/home/deploy/stack/newwhats.clube67.com/newwhats.local/frontend/
|
||||
|
||||
log "🚚 Despachando Plugins e arquivos compartilhados..."
|
||||
rsync -avz --delete /home/deploy/stack/newwhats.clube67.com/newwhats.local/plugins/ deploy@10.99.0.1:/home/deploy/stack/newwhats.clube67.com/newwhats.local/plugins/
|
||||
|
||||
# 5. Reiniciar os serviços de produção na VPS 1
|
||||
log "🔄 Reiniciando containers na VPS 1..."
|
||||
ssh -o BatchMode=yes deploy@10.99.0.1 "cd /home/deploy/stack/newwhats.clube67.com && DOCKER_HOST=unix:///run/user/1000/docker.sock docker compose restart newwhats-backend newwhats-frontend"
|
||||
|
||||
# 6. Salvar incremento de versão no Git
|
||||
log "💾 Comitando o incremento de versão de volta para o repositório central..."
|
||||
cd /home/deploy/stack/newwhats.clube67.com/newwhats.local
|
||||
git add deploys.json version.json frontend/public/deploys.json frontend/public/version.json
|
||||
git commit -m "chore(deploy): bump version"
|
||||
git push origin main
|
||||
|
||||
log "✅ Deploy concluído com absoluto sucesso!"
|
||||
Reference in New Issue
Block a user