# 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