VigilanzaTurni/deploy/deploy.sh
marco370 3cdc6931bb Improve deployment process by generating secure passwords
Update deployment scripts to automatically generate secure PostgreSQL passwords, store them securely, and use them in environment configuration.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 99f0fce6-9386-489a-9632-1d81223cab44
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/99f0fce6-9386-489a-9632-1d81223cab44/H8Wilyj
2025-10-16 07:15:54 +00:00

58 lines
1.4 KiB
Bash

#!/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 TUTTE le dipendenze (serve per build e migrations)
echo "📥 Installazione dipendenze (include devDependencies)..."
npm ci
# Build frontend
echo "🏗️ Build frontend Vite..."
export NODE_ENV=production
npm run build
# Database migrations (serve Drizzle che è devDependency)
echo "🗄️ Verifica database schema..."
npm run db:push || true
# Rimuovi devDependencies dopo build e migrations
echo "🧹 Pulizia devDependencies (mantiene solo production)..."
npm prune --production
# 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