feat(deploy): add GitOps automation - listener 9003, update-version.js, deploy-prod.sh GitOps
continuous-integration/webhook Deploy concluído (VPS4)
continuous-integration/webhook Deploy concluído (VPS4)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dental-image-server",
|
"name": "dental-image-server",
|
||||||
"version": "2.0.5",
|
"version": "2.1.1",
|
||||||
"description": "Servidor Socket.IO para receber e processar imagens dentais com interface web",
|
"description": "Servidor Socket.IO para receber e processar imagens dentais com interface web",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
<div class="logo-icon">
|
<div class="logo-icon">
|
||||||
<i class="fa-solid fa-tooth"></i>
|
<i class="fa-solid fa-tooth"></i>
|
||||||
</div>
|
</div>
|
||||||
<h2>RF Dental <span style="font-size: 10px; opacity: 0.5; font-weight: 500; margin-left: 4px; vertical-align: middle;">v2.1.2</span></h2>
|
<h2>RF Dental <span style="font-size: 10px; opacity: 0.5; font-weight: 500; margin-left: 4px; vertical-align: middle;">v2.1.1</span></h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav class="sidebar-nav">
|
<nav class="sidebar-nav">
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
2.1.0
|
2.1.1
|
||||||
|
|||||||
+39
-19
@@ -1,20 +1,41 @@
|
|||||||
#!/bin/bash
|
#!/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
|
set -e
|
||||||
|
|
||||||
PROD_VPS="10.99.0.1"
|
PROD_VPS="10.99.0.1"
|
||||||
PROD_USER="deploy"
|
PROD_USER="deploy"
|
||||||
PROD_PATH="/home/deploy/stack/rx.scoreodonto.com"
|
PROD_PATH="/home/deploy/stack/rx.scoreodonto.com"
|
||||||
|
LOG_FILE="/home/deploy/stack/webhook-listener/deploy.log"
|
||||||
LOG_TAG="[rx.scoreodonto.com]"
|
LOG_TAG="[rx.scoreodonto.com]"
|
||||||
|
DOCKER_HOST_REMOTE="unix:///run/user/1000/docker.sock"
|
||||||
|
|
||||||
echo "========================================================"
|
LOCK_FILE="/tmp/deploy-rx-scoreodonto.lock"
|
||||||
echo "$LOG_TAG INICIANDO DEPLOY PARA PRODUCAO (VPS 1)"
|
if [ -f "$LOCK_FILE" ]; then
|
||||||
echo "========================================================"
|
echo "🚨 Deploy já em andamento!" | tee -a "$LOG_FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
touch "$LOCK_FILE"
|
||||||
|
trap 'rm -f "$LOCK_FILE"' EXIT
|
||||||
|
|
||||||
echo "$LOG_TAG Atualizando repositório local na VPS 4..."
|
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 fetch origin main
|
||||||
git reset --hard origin/main
|
git reset --hard origin/main
|
||||||
|
|
||||||
echo "$LOG_TAG Transferindo arquivos para VPS 1 via rsync..."
|
# 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 \
|
rsync -avz --delete \
|
||||||
--exclude '.git' \
|
--exclude '.git' \
|
||||||
--exclude '.env' \
|
--exclude '.env' \
|
||||||
@@ -23,24 +44,23 @@ rsync -avz --delete \
|
|||||||
--exclude 'processed' \
|
--exclude 'processed' \
|
||||||
--exclude 'data' \
|
--exclude 'data' \
|
||||||
--exclude 'dental-server/updates' \
|
--exclude 'dental-server/updates' \
|
||||||
${PROD_PATH}/ \
|
"$PROD_PATH/" \
|
||||||
${PROD_USER}@${PROD_VPS}:${PROD_PATH}/
|
"${PROD_USER}@${PROD_VPS}:${PROD_PATH}/"
|
||||||
|
|
||||||
echo "$LOG_TAG Recriando containers na VPS 1..."
|
# 4. Build + swap do container na VPS1 (sem downtime)
|
||||||
ssh -o BatchMode=yes -o StrictHostKeyChecking=no ${PROD_USER}@${PROD_VPS} "
|
log "🐳 docker compose build + up na VPS1..."
|
||||||
|
ssh -o BatchMode=yes -o StrictHostKeyChecking=no "${PROD_USER}@${PROD_VPS}" "
|
||||||
set -e
|
set -e
|
||||||
cd ${PROD_PATH}
|
cd ${PROD_PATH}
|
||||||
export DOCKER_HOST=unix:///run/user/1000/docker.sock
|
export DOCKER_HOST=${DOCKER_HOST_REMOTE}
|
||||||
|
|
||||||
echo '${LOG_TAG} Recriando imagem com novos arquivos...'
|
|
||||||
docker compose build app
|
docker compose build app
|
||||||
|
|
||||||
echo '${LOG_TAG} Subindo novo container sem derrubar o atual...'
|
|
||||||
docker compose up -d --no-deps app
|
docker compose up -d --no-deps app
|
||||||
|
|
||||||
echo '${LOG_TAG} Container atualizado com sucesso!'
|
|
||||||
"
|
"
|
||||||
|
|
||||||
echo "========================================================"
|
# 5. Commit do bump de versão de volta ao Gitea (listener ignora → sem loop)
|
||||||
echo "$LOG_TAG DEPLOY CONCLUIDO SEM DOWNTIME!"
|
log "💾 git commit + push do bump de versão..."
|
||||||
echo "========================================================"
|
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!"
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
// update-version.js — sincroniza version.txt → package.json + index.html
|
||||||
|
// Incrementa o PATCH automaticamente a cada deploy.
|
||||||
|
// Fonte de verdade: dental-server/version.txt
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const versionFile = path.join(__dirname, 'dental-server', 'version.txt');
|
||||||
|
const packageFile = path.join(__dirname, 'dental-server', 'package.json');
|
||||||
|
const indexFile = path.join(__dirname, 'dental-server', 'public', 'index.html');
|
||||||
|
|
||||||
|
const current = fs.readFileSync(versionFile, 'utf8').trim();
|
||||||
|
const parts = current.split('.').map(Number);
|
||||||
|
parts[2]++; // bump PATCH
|
||||||
|
const next = parts.join('.');
|
||||||
|
|
||||||
|
// version.txt
|
||||||
|
fs.writeFileSync(versionFile, next + '\n');
|
||||||
|
|
||||||
|
// package.json
|
||||||
|
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
|
||||||
|
pkg.version = next;
|
||||||
|
fs.writeFileSync(packageFile, JSON.stringify(pkg, null, 2) + '\n');
|
||||||
|
|
||||||
|
// index.html — substitui qualquer v{X.Y.Z} dentro do <span> da sidebar
|
||||||
|
let html = fs.readFileSync(indexFile, 'utf8');
|
||||||
|
html = html.replace(
|
||||||
|
/(RF Dental.*?<span[^>]*>)\s*v[\d.]+\s*(<\/span>)/s,
|
||||||
|
`$1v${next}$2`
|
||||||
|
);
|
||||||
|
fs.writeFileSync(indexFile, html);
|
||||||
|
|
||||||
|
console.log(`version: ${current} → ${next}`);
|
||||||
Reference in New Issue
Block a user