VigilanzaTurni/.gitlab-ci.yml
marco370 5a51a65218 Add deployment guide and scripts for automated server setup and deployment
Adds a comprehensive DEPLOYMENT.md guide, a setup-server.sh script for AlmaLinux 9 to install Node.js, PostgreSQL, Nginx, and PM2, a deploy.sh script for CI/CD deployment, an nginx.conf for server configuration, and a push-to-gitlab.sh helper script for Replit integration.

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:12:27 +00:00

121 lines
3.2 KiB
YAML

# GitLab CI/CD Pipeline per VigilanzaTurni
# Deployment automatico su AlmaLinux 9
stages:
- build
- test
- deploy
variables:
NODE_VERSION: "20"
APP_DIR: "/var/www/vigilanza-turni"
# Cache per velocizzare build
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
- .npm/
# =================== BUILD STAGE ===================
build:
stage: build
image: node:20-alpine
script:
- echo "📦 Installazione dipendenze..."
- npm ci
- echo "🏗️ Build TypeScript..."
- npm run build
- echo "✅ Build completato"
artifacts:
paths:
- dist/
- node_modules/
expire_in: 1 hour
only:
- main
- develop
# =================== TEST STAGE ===================
test:
stage: test
image: node:20-alpine
script:
- echo "🧪 Esecuzione test..."
- npm run lint || true
- echo "✅ Test completati"
only:
- main
- develop
# =================== DEPLOY PRODUCTION ===================
deploy_production:
stage: deploy
image: alpine:latest
before_script:
- apk add --no-cache openssh-client rsync
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -H $DEPLOY_HOST >> ~/.ssh/known_hosts
script:
- echo "🚀 Deployment su server produzione..."
# Sync files to server
- rsync -avz --delete --exclude='.git' --exclude='node_modules' --exclude='.env' ./ $DEPLOY_USER@$DEPLOY_HOST:$APP_DIR/
# Execute deployment script on server
- ssh $DEPLOY_USER@$DEPLOY_HOST "cd $APP_DIR && bash deploy/deploy.sh"
- echo "✅ Deployment completato!"
- echo "🌐 Applicazione disponibile su: https://$DEPLOY_DOMAIN"
environment:
name: production
url: https://$DEPLOY_DOMAIN
only:
- main
when: manual
# =================== DEPLOY STAGING (opzionale) ===================
deploy_staging:
stage: deploy
image: alpine:latest
before_script:
- apk add --no-cache openssh-client rsync
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -H $DEPLOY_HOST >> ~/.ssh/known_hosts
script:
- echo "🧪 Deployment su staging..."
- rsync -avz --delete --exclude='.git' --exclude='node_modules' --exclude='.env' ./ $DEPLOY_USER@$DEPLOY_HOST:/var/www/vigilanza-turni-staging/
- ssh $DEPLOY_USER@$DEPLOY_HOST "cd /var/www/vigilanza-turni-staging && bash deploy/deploy.sh"
- echo "✅ Staging deployment completato!"
environment:
name: staging
url: https://staging.$DEPLOY_DOMAIN
only:
- develop
when: manual
# =================== ROLLBACK (emergenza) ===================
rollback:
stage: deploy
image: alpine:latest
before_script:
- apk add --no-cache openssh-client
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -H $DEPLOY_HOST >> ~/.ssh/known_hosts
script:
- echo "⏮️ Rollback alla versione precedente..."
- ssh $DEPLOY_USER@$DEPLOY_HOST "cd $APP_DIR && git checkout HEAD~1 && bash deploy/deploy.sh"
- echo "✅ Rollback completato"
only:
- main
when: manual