Add automated deployment with versioning and database backup

Introduces a new deployment script (push-gitlab.sh) and documentation (GITLAB-DEPLOY.md) to automate pushing code to GitLab. The system supports semantic versioning (patch, minor, major) for releases and automatically backs up the database before each deployment. It also includes instructions for configuring GitLab credentials via a `git.env` file.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 42d8028a-fa71-4ec2-938c-e43eedf7df01
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/42d8028a-fa71-4ec2-938c-e43eedf7df01/Z1LDqzu
This commit is contained in:
marco370 2025-10-17 06:38:57 +00:00
parent be38d9a68f
commit acc1939f44
3 changed files with 410 additions and 0 deletions

View File

@ -19,6 +19,10 @@ externalPort = 80
localPort = 33035 localPort = 33035
externalPort = 3001 externalPort = 3001
[[ports]]
localPort = 39511
externalPort = 3003
[[ports]] [[ports]]
localPort = 41343 localPort = 41343
externalPort = 3000 externalPort = 3000

326
GITLAB-DEPLOY.md Normal file
View File

@ -0,0 +1,326 @@
# 🚀 VigilanzaTurni - Guida Deployment GitLab
Sistema di deployment automatico con **versioning semantico** e **backup database**.
---
## 📋 Indice
1. [Configurazione Iniziale](#configurazione-iniziale)
2. [Come Fare il Deploy](#come-fare-il-deploy)
3. [Versioning Semantico](#versioning-semantico)
4. [Backup Database](#backup-database)
5. [Troubleshooting](#troubleshooting)
---
## 🔧 Configurazione Iniziale
### 1. Crea Personal Access Token su GitLab
1. Vai su **GitLab****Preferenze** → **Access Tokens**
- URL: https://gitlab.com/-/profile/personal_access_tokens
2. Crea nuovo token con nome: `VigilanzaTurni Deploy`
3. Seleziona questi **permessi** (scopes):
- ✅ `api` - Accesso completo API
- ✅ `read_repository` - Lettura repository
- ✅ `write_repository` - Scrittura repository
4. **Salva il token** (lo vedrai una sola volta!)
### 2. Configura git.env
Crea il file `git.env` nella root del progetto:
```bash
# Il file git.env è già presente come template
nano git.env
```
Contenuto `git.env`:
```bash
GITLAB_USER=tuo-username
GITLAB_TOKEN=glpat-xxxxxxxxxxxxxxxxxxxx
GITLAB_REPO=https://gitlab.com/tuo-username/vigilanzaturni.git
GITLAB_BRANCH=main
```
**⚠️ IMPORTANTE**:
- Il file `git.env` è già in `.gitignore` - **non verrà mai committato**
- Conserva il token in un posto sicuro (password manager)
### 3. Verifica Repository GitLab
Assicurati che il repository esista su GitLab:
```bash
# Crea repository su GitLab web UI
# Oppure usa GitLab CLI
```
---
## 🚀 Come Fare il Deploy
### Metodo Rapido (Consigliato)
```bash
# Rendi eseguibile (solo prima volta)
chmod +x push-gitlab.sh
# Deploy patch (bug fix, piccole modifiche)
./push-gitlab.sh
# Deploy minor (nuove funzionalità)
./push-gitlab.sh minor
# Deploy major (breaking changes)
./push-gitlab.sh major
```
### Metodo Completo
```bash
# Usa lo script principale per maggior controllo
./deploy-to-gitlab.sh [patch|minor|major]
```
---
## 📊 Versioning Semantico
Il sistema usa **Semantic Versioning 2.0.0**: `MAJOR.MINOR.PATCH`
### Formato Versione: `X.Y.Z`
| Componente | Quando Incrementare | Esempio |
|------------|---------------------|---------|
| **MAJOR (X)** | Breaking changes, API incompatibili | 1.5.3 → **2.0.0** |
| **MINOR (Y)** | Nuove funzionalità retrocompatibili | 1.5.3 → **1.6.0** |
| **PATCH (Z)** | Bug fix, piccole correzioni | 1.5.3 → **1.5.4** |
### Esempi Pratici
#### PATCH (default) - Bug fix
```bash
./push-gitlab.sh # 1.0.0 → 1.0.1
./push-gitlab.sh patch # 1.0.1 → 1.0.2
```
**Quando usare**:
- ✅ Correzione bug
- ✅ Typo nel codice
- ✅ Performance minori
- ✅ Aggiornamento dipendenze patch
#### MINOR - Nuove funzionalità
```bash
./push-gitlab.sh minor # 1.0.5 → 1.1.0
```
**Quando usare**:
- ✅ Nuova pagina/sezione
- ✅ Nuova API endpoint
- ✅ Feature richiesta da cliente
- ✅ Miglioramento UX significativo
#### MAJOR - Breaking changes
```bash
./push-gitlab.sh major # 1.5.2 → 2.0.0
```
**Quando usare**:
- ✅ Cambio architettura database
- ✅ Rimozione API/endpoint
- ✅ Cambio sistema autenticazione
- ✅ Migrazione framework
---
## 💾 Backup Database
### Automatico ad Ogni Deploy
Lo script **crea automaticamente** un backup del database:
```
database-backups/
└── vigilanzaturni_v1.0.1_20250117_143022.sql.gz
└── vigilanzaturni_v1.0.2_20250117_150315.sql.gz
└── vigilanzaturni_v1.1.0_20250118_091145.sql.gz
```
### Formato Nome File
```
vigilanzaturni_v{VERSION}_{TIMESTAMP}.sql.gz
```
- **VERSION**: Versione deployment (es. 1.0.1)
- **TIMESTAMP**: Data e ora (YYYYMMDD_HHMMSS)
### Retention Policy
- ✅ Compressi con gzip (risparmio spazio ~90%)
- ✅ Mantiene ultimi **10 backup** automaticamente
- ✅ Backup più vecchi eliminati automaticamente
### Ripristino Manuale
Se necessario ripristinare un backup:
```bash
# 1. Decomprimi
gunzip database-backups/vigilanzaturni_v1.0.1_20250117_143022.sql.gz
# 2. Ripristina
psql $DATABASE_URL < database-backups/vigilanzaturni_v1.0.1_20250117_143022.sql
```
---
## 🔍 Troubleshooting
### ❌ Errore: "git.env non trovato"
**Soluzione**:
```bash
# Crea git.env e configura credenziali
nano git.env
```
### ❌ Errore: "Authentication failed"
**Possibili cause**:
1. Token GitLab scaduto
2. Token senza permessi corretti
3. Username errato
**Soluzione**:
```bash
# 1. Verifica credenziali in git.env
cat git.env
# 2. Crea nuovo token su GitLab
# https://gitlab.com/-/profile/personal_access_tokens
# 3. Aggiorna GITLAB_TOKEN in git.env
```
### ❌ Errore: "Remote repository not found"
**Soluzione**:
```bash
# Verifica URL repository in git.env
# Deve essere: https://gitlab.com/USERNAME/REPO.git
# Verifica che il repository esista su GitLab
```
### ❌ Backup Database Fallito
**Soluzione**:
```bash
# Verifica DATABASE_URL
echo $DATABASE_URL
# Verifica pg_dump installato
which pg_dump
# Test manuale backup
pg_dump $DATABASE_URL > test-backup.sql
```
### ⚠️ Warning: "Push failed"
**Possibili cause**:
1. Repository protetto (protected branch)
2. Permessi insufficienti
3. Conflitti git
**Soluzione**:
```bash
# 1. Verifica branch protection su GitLab
# Settings → Repository → Protected Branches
# 2. Verifica permessi token (deve essere Maintainer/Owner)
# 3. Forza push (con cautela!)
git push gitlab main --force
```
---
## 📈 Workflow Consigliato
### Sviluppo Giornaliero
```bash
# Ogni bug fix o piccola modifica
./push-gitlab.sh # 1.0.0 → 1.0.1 → 1.0.2
```
### Fine Settimana (Nuove Feature)
```bash
# Dopo aver completato una feature
./push-gitlab.sh minor # 1.0.5 → 1.1.0
```
### Release Maggiori (Milestone)
```bash
# Dopo cambiamenti architetturali importanti
./push-gitlab.sh major # 1.5.2 → 2.0.0
```
---
## 📝 File Generati
| File | Descrizione | Committato su Git |
|------|-------------|-------------------|
| `git.env` | Credenziali GitLab | ❌ No (in .gitignore) |
| `version.json` | Versione corrente | ✅ Sì |
| `database-backups/*.sql.gz` | Backup DB | ❌ No (in .gitignore) |
| `deploy-to-gitlab.sh` | Script deployment | ✅ Sì |
| `push-gitlab.sh` | Helper script | ✅ Sì |
---
## 🎯 Best Practices
### ✅ DO
- Fai deploy **frequenti** (patch)
- Usa **minor** per nuove feature complete
- Usa **major** solo per breaking changes
- Testa localmente prima del deploy
- Verifica backup database dopo deploy importante
### ❌ DON'T
- Non committare `git.env` (già protetto)
- Non saltare versioni manualmente
- Non modificare `version.json` manualmente
- Non eliminare backup recenti manualmente
---
## 📞 Supporto
In caso di problemi:
1. Controlla version.json: `cat version.json`
2. Verifica configurazione: `cat git.env`
3. Testa connessione GitLab manualmente
4. Controlla se il repository esiste
---
**Versione Documento**: 1.0.0
**Ultimo Aggiornamento**: 2025-01-17
**Compatibilità**: VigilanzaTurni v1.0.0+

80
push-gitlab.sh Executable file
View File

@ -0,0 +1,80 @@
#!/bin/bash
# =============================================================================
# VigilanzaTurni - Quick Push to GitLab
# =============================================================================
# Script semplificato per deployment rapido
# =============================================================================
# Colori
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════╗"
echo "║ VigilanzaTurni - GitLab Deployment ║"
echo "╔═══════════════════════════════════════════════╝"
echo -e "${NC}"
# Mostra uso
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "Uso:"
echo ""
echo " ./push-gitlab.sh → Patch version (1.0.0 → 1.0.1)"
echo " ./push-gitlab.sh minor → Minor version (1.0.5 → 1.1.0)"
echo " ./push-gitlab.sh major → Major version (1.1.5 → 2.0.0)"
echo ""
echo "Esempi:"
echo ""
echo " ./push-gitlab.sh # Fix bug, piccole modifiche"
echo " ./push-gitlab.sh minor # Nuove funzionalità"
echo " ./push-gitlab.sh major # Breaking changes"
echo ""
exit 0
fi
# Determina tipo incremento
INCREMENT_TYPE=${1:-patch}
case $INCREMENT_TYPE in
patch)
echo -e "${GREEN}📦 Deploy PATCH${NC} - Bug fix, piccole modifiche"
;;
minor)
echo -e "${YELLOW}🆕 Deploy MINOR${NC} - Nuove funzionalità"
;;
major)
echo -e "${BLUE}🚀 Deploy MAJOR${NC} - Breaking changes"
;;
*)
echo -e "❌ Tipo non valido: $INCREMENT_TYPE"
echo "Usa: patch, minor, o major"
exit 1
;;
esac
echo ""
# Verifica git.env
if [ ! -f "git.env" ]; then
echo "⚠️ git.env non trovato!"
echo ""
echo "Crea il file git.env con queste informazioni:"
echo ""
echo "GITLAB_USER=tuo-username"
echo "GITLAB_TOKEN=tuo-token-personale"
echo "GITLAB_REPO=https://gitlab.com/tuo-username/vigilanzaturni.git"
echo "GITLAB_BRANCH=main"
echo ""
echo "Ottieni il token su: https://gitlab.com/-/profile/personal_access_tokens"
echo "Permessi richiesti: api, read_repository, write_repository"
echo ""
exit 1
fi
# Esegui deployment
./deploy-to-gitlab.sh "$INCREMENT_TYPE"
exit $?