#!/bin/bash set -e # Script di deployment automatico per VigilanzaTurni # Eseguito da GitLab CI/CD Runner APP_DIR="/var/www/vigilanza-turni" APP_NAME="vigilanza-turni" echo "🚀 Deployment VigilanzaTurni - $(date)" # Vai alla directory applicazione cd $APP_DIR # Pull ultime modifiche (già fatto da GitLab Runner) echo "📦 Repository aggiornato" # Installa dipendenze echo "📥 Installazione dipendenze..." npm ci --production # Build frontend echo "🏗️ Build frontend Vite..." export NODE_ENV=production npm run build # Database migrations (se necessario) echo "🗄️ Verifica database schema..." npm run db:push || true # Restart applicazione con PM2 echo "🔄 Restart applicazione..." if pm2 show $APP_NAME > /dev/null 2>&1; then pm2 reload $APP_NAME --update-env else pm2 start npm --name $APP_NAME -- start pm2 save fi # Health check echo "🏥 Health check..." sleep 5 if pm2 show $APP_NAME | grep -q "online"; then echo "✅ Deployment completato con successo!" pm2 logs $APP_NAME --lines 20 --nostream else echo "❌ Errore: applicazione non online" pm2 logs $APP_NAME --lines 50 --nostream exit 1 fi echo "📊 Status PM2:" pm2 status