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
This commit is contained in:
parent
5a51a65218
commit
3cdc6931bb
@ -66,12 +66,17 @@ Lo script installerà:
|
||||
Lo script crea automaticamente:
|
||||
- Database: `vigilanza_turni`
|
||||
- User: `vigilanza_user`
|
||||
- Password: `ChangeMe_ProductionPassword123!` ⚠️ **CAMBIALA!**
|
||||
- Password: **Generata automaticamente** (mostrata a fine setup)
|
||||
|
||||
⚠️ **IMPORTANTE**: Salva la password mostrata al termine del setup!
|
||||
|
||||
```bash
|
||||
# Cambia password PostgreSQL
|
||||
# La password è salvata anche in:
|
||||
cat /root/.vigilanza_db_password
|
||||
|
||||
# Se persa, puoi cambiarla con:
|
||||
sudo -u postgres psql
|
||||
ALTER USER vigilanza_user WITH PASSWORD 'TuaPasswordSicura123!';
|
||||
ALTER USER vigilanza_user WITH PASSWORD 'NuovaPasswordSicura123!';
|
||||
\q
|
||||
```
|
||||
|
||||
@ -178,9 +183,14 @@ cp .env.production.example .env
|
||||
nano .env
|
||||
```
|
||||
|
||||
Configura:
|
||||
Configura usando la password PostgreSQL generata durante setup:
|
||||
|
||||
```bash
|
||||
DATABASE_URL=postgresql://vigilanza_user:TuaPasswordSicura@localhost:5432/vigilanza_turni
|
||||
# Recupera password DB
|
||||
DB_PASS=$(grep PGPASSWORD /root/.vigilanza_db_password | cut -d= -f2)
|
||||
|
||||
# Configura .env
|
||||
DATABASE_URL=postgresql://vigilanza_user:${DB_PASS}@localhost:5432/vigilanza_turni
|
||||
SESSION_SECRET=$(openssl rand -base64 32)
|
||||
REPLIT_DOMAINS=vigilanza.tuodominio.it
|
||||
```
|
||||
|
||||
172
QUICKSTART-DEPLOYMENT.md
Normal file
172
QUICKSTART-DEPLOYMENT.md
Normal file
@ -0,0 +1,172 @@
|
||||
# 🚀 Quick Start - Deployment VigilanzaTurni
|
||||
|
||||
Guida rapida per deployment da Replit → GitLab → Server AlmaLinux 9
|
||||
|
||||
## 📝 Checklist Pre-Deployment
|
||||
|
||||
- [ ] Server AlmaLinux 9 disponibile (min 2GB RAM)
|
||||
- [ ] Dominio configurato (es. vigilanza.tuodominio.it)
|
||||
- [ ] Account GitLab su git.alfacom.it
|
||||
- [ ] SSH access al server
|
||||
|
||||
---
|
||||
|
||||
## ⚡ Setup Rapido (15 minuti)
|
||||
|
||||
### 1️⃣ Setup Server (5 min)
|
||||
|
||||
```bash
|
||||
# SSH nel server
|
||||
ssh root@ip-del-server
|
||||
|
||||
# Download e esegui setup automatico
|
||||
curl -o setup.sh https://git.alfacom.it/marco/VigilanzaTurni/-/raw/main/deploy/setup-server.sh
|
||||
chmod +x setup.sh
|
||||
sudo bash setup.sh
|
||||
|
||||
# ⚠️ IMPORTANTE: Salva la password PostgreSQL mostrata!
|
||||
```
|
||||
|
||||
### 2️⃣ Configura GitLab CI/CD (3 min)
|
||||
|
||||
**Genera SSH Key:**
|
||||
```bash
|
||||
# Sul tuo PC
|
||||
ssh-keygen -t ed25519 -C "gitlab-deploy" -f ~/.ssh/gitlab-deploy
|
||||
ssh-copy-id -i ~/.ssh/gitlab-deploy.pub root@ip-del-server
|
||||
cat ~/.ssh/gitlab-deploy # Copia output
|
||||
```
|
||||
|
||||
**GitLab → Settings → CI/CD → Variables:**
|
||||
|
||||
| Nome | Valore |
|
||||
|------|--------|
|
||||
| `SSH_PRIVATE_KEY` | [chiave privata copiata sopra] |
|
||||
| `DEPLOY_HOST` | ip-del-server |
|
||||
| `DEPLOY_USER` | root |
|
||||
| `DEPLOY_DOMAIN` | vigilanza.tuodominio.it |
|
||||
|
||||
### 3️⃣ Configura Replit (2 min)
|
||||
|
||||
```bash
|
||||
# In Replit Shell
|
||||
git remote add production https://git.alfacom.it/marco/VigilanzaTurni.git
|
||||
|
||||
# Crea Personal Access Token su GitLab e salvalo in Replit Secrets
|
||||
# GitLab → User Settings → Access Tokens → write_repository
|
||||
```
|
||||
|
||||
### 4️⃣ Configura Server .env (3 min)
|
||||
|
||||
```bash
|
||||
# Sul server
|
||||
cd /var/www/vigilanza-turni
|
||||
|
||||
# Clone iniziale
|
||||
git clone https://git.alfacom.it/marco/VigilanzaTurni.git .
|
||||
|
||||
# Crea .env
|
||||
cp .env.production.example .env
|
||||
nano .env
|
||||
```
|
||||
|
||||
**Inserisci:**
|
||||
```bash
|
||||
# Password DB dal setup (vedi /root/.vigilanza_db_password)
|
||||
DATABASE_URL=postgresql://vigilanza_user:PASSWORD_GENERATA@localhost:5432/vigilanza_turni
|
||||
SESSION_SECRET=$(openssl rand -base64 32)
|
||||
REPLIT_DOMAINS=vigilanza.tuodominio.it
|
||||
```
|
||||
|
||||
### 5️⃣ Nginx e SSL (2 min)
|
||||
|
||||
```bash
|
||||
# Copia config Nginx
|
||||
sudo cp deploy/nginx.conf /etc/nginx/conf.d/vigilanza-turni.conf
|
||||
|
||||
# Modifica con il tuo dominio
|
||||
sudo nano /etc/nginx/conf.d/vigilanza-turni.conf
|
||||
# Sostituisci "tuodominio.it" → "vigilanza.tuodominio.it"
|
||||
|
||||
# Test e reload
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
|
||||
# SSL Certificate
|
||||
sudo certbot --nginx -d vigilanza.tuodominio.it
|
||||
```
|
||||
|
||||
### 6️⃣ Primo Deploy (1 min)
|
||||
|
||||
```bash
|
||||
# Sul server
|
||||
cd /var/www/vigilanza-turni
|
||||
bash deploy/deploy.sh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔄 Workflow Quotidiano
|
||||
|
||||
### Da Replit → Produzione
|
||||
|
||||
```bash
|
||||
# 1. Fai modifiche in Replit
|
||||
# 2. Push a GitLab
|
||||
bash push-to-gitlab.sh
|
||||
|
||||
# 3. Vai su GitLab
|
||||
https://git.alfacom.it/marco/VigilanzaTurni/-/pipelines
|
||||
|
||||
# 4. Clicca su "deploy_production" quando pronto
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📊 Comandi Utili
|
||||
|
||||
```bash
|
||||
# Status applicazione
|
||||
pm2 status
|
||||
|
||||
# Logs real-time
|
||||
pm2 logs vigilanza-turni
|
||||
|
||||
# Restart
|
||||
pm2 restart vigilanza-turni
|
||||
|
||||
# Backup database
|
||||
sudo -u postgres pg_dump vigilanza_turni > backup_$(date +%Y%m%d).sql
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🆘 Problemi Comuni
|
||||
|
||||
**App non risponde:**
|
||||
```bash
|
||||
pm2 restart vigilanza-turni
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
**Errore database:**
|
||||
```bash
|
||||
# Verifica password in .env corrisponde a quella in /root/.vigilanza_db_password
|
||||
cat /root/.vigilanza_db_password
|
||||
```
|
||||
|
||||
**SSL scaduto:**
|
||||
```bash
|
||||
sudo certbot renew
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📚 Documentazione Completa
|
||||
|
||||
Per dettagli completi: [DEPLOYMENT.md](./DEPLOYMENT.md)
|
||||
|
||||
---
|
||||
|
||||
**Setup completato?** ✅ Vai su https://vigilanza.tuodominio.it
|
||||
12
deploy/deploy.sh
Executable file → Normal file
12
deploy/deploy.sh
Executable file → Normal file
@ -15,19 +15,23 @@ cd $APP_DIR
|
||||
# Pull ultime modifiche (già fatto da GitLab Runner)
|
||||
echo "📦 Repository aggiornato"
|
||||
|
||||
# Installa dipendenze
|
||||
echo "📥 Installazione dipendenze..."
|
||||
npm ci --production
|
||||
# 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 (se necessario)
|
||||
# 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
|
||||
|
||||
18
deploy/setup-server.sh
Executable file → Normal file
18
deploy/setup-server.sh
Executable file → Normal file
@ -48,16 +48,24 @@ postgresql-setup --initdb
|
||||
systemctl enable postgresql
|
||||
systemctl start postgresql
|
||||
|
||||
# Generazione password sicura PostgreSQL
|
||||
DB_PASSWORD=$(openssl rand -base64 32 | tr -d "=+/" | cut -c1-25)
|
||||
|
||||
# Creazione database e utente
|
||||
log_info "Configurazione database..."
|
||||
sudo -u postgres psql << EOF
|
||||
CREATE DATABASE vigilanza_turni;
|
||||
CREATE USER vigilanza_user WITH ENCRYPTED PASSWORD 'ChangeMe_ProductionPassword123!';
|
||||
CREATE USER vigilanza_user WITH ENCRYPTED PASSWORD '${DB_PASSWORD}';
|
||||
GRANT ALL PRIVILEGES ON DATABASE vigilanza_turni TO vigilanza_user;
|
||||
\c vigilanza_turni
|
||||
GRANT ALL ON SCHEMA public TO vigilanza_user;
|
||||
EOF
|
||||
|
||||
# Salva password in file sicuro
|
||||
echo "PGPASSWORD=${DB_PASSWORD}" > /root/.vigilanza_db_password
|
||||
chmod 600 /root/.vigilanza_db_password
|
||||
log_info "Password PostgreSQL salvata in: /root/.vigilanza_db_password"
|
||||
|
||||
# Configurazione PostgreSQL per connessioni locali
|
||||
log_info "Configurazione autenticazione PostgreSQL..."
|
||||
PG_HBA="/var/lib/pgsql/data/pg_hba.conf"
|
||||
@ -100,9 +108,13 @@ log_info "================================================"
|
||||
log_info ""
|
||||
log_warn "PROSSIMI PASSI:"
|
||||
echo "1. Configura il DNS per puntare questo server"
|
||||
echo "2. Modifica la password PostgreSQL in /var/www/vigilanza-turni/.env"
|
||||
echo "2. Copia DATABASE_URL qui sotto nel file /var/www/vigilanza-turni/.env"
|
||||
echo "3. Ottieni certificato SSL: sudo certbot --nginx -d tuodominio.it"
|
||||
echo "4. Esegui il primo deployment con GitLab CI/CD"
|
||||
echo ""
|
||||
log_warn "⚠️ IMPORTANTE - Salva questa password (disponibile in /root/.vigilanza_db_password):"
|
||||
echo ""
|
||||
log_info "DATABASE_URL per .env:"
|
||||
echo "postgresql://vigilanza_user:ChangeMe_ProductionPassword123!@localhost:5432/vigilanza_turni"
|
||||
echo "postgresql://vigilanza_user:${DB_PASSWORD}@localhost:5432/vigilanza_turni"
|
||||
echo ""
|
||||
log_warn "Password PostgreSQL generata automaticamente: ${DB_PASSWORD}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user