# =================================================================== # GitHub Actions - Automatisches Deployment auf Proxmox-Server # Meldestelle Project - CI/CD Pipeline # =================================================================== name: Deploy Proxmox (manual) permissions: contents: read concurrency: group: deploy-proxmox-${{ github.ref }} cancel-in-progress: true on: workflow_dispatch: # Manueller Trigger env: DOCKER_COMPOSE_VERSION: "v2.20.0" jobs: # =================================================================== # Build & Test # =================================================================== build-and-test: runs-on: ubuntu-latest steps: - name: Checkout Code uses: actions/checkout@v6 - name: Set up JDK 21 uses: actions/setup-java@v5 with: java-version: '21' distribution: 'temurin' - name: Cache Gradle dependencies uses: actions/cache@v4 with: path: | ~/.gradle/caches ~/.gradle/wrapper key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle- - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Static Analysis run: ./gradlew staticAnalysis --no-daemon || true - name: Build (all) run: ./gradlew build -x test --no-daemon - name: Test (all) run: ./gradlew test --no-daemon || true # Allow failure for now # =================================================================== # Deploy to Proxmox (nur bei main branch) # =================================================================== deploy: needs: build-and-test runs-on: ubuntu-latest if: github.event_name == 'workflow_dispatch' steps: - name: Checkout Code uses: actions/checkout@v6 - name: Setup SSH Key uses: webfactory/ssh-agent@v0.8.0 with: ssh-private-key: ${{ secrets.PROXMOX_SSH_PRIVATE_KEY }} - name: Add Proxmox to known_hosts run: | ssh-keyscan -H ${{ secrets.PROXMOX_HOST }} >> ~/.ssh/known_hosts - name: Deploy to Proxmox Server env: PROXMOX_HOST: ${{ secrets.PROXMOX_HOST }} PROXMOX_USER: ${{ secrets.PROXMOX_USER }} DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }} run: | ssh $PROXMOX_USER@$PROXMOX_HOST << 'ENDSSH' set -e # Navigate to deployment directory cd ${{ secrets.DEPLOY_PATH }} # Pull latest changes echo "๐Ÿ”„ Pulling latest changes from GitHub..." git fetch origin git reset --hard origin/main # Create backup of current environment echo "๐Ÿ’พ Creating backup..." cp .env .env.backup.$(date +%Y%m%d_%H%M%S) || true # Stop existing services echo "๐Ÿ›‘ Stopping existing services..." docker compose --env-file docker/.env -f docker/docker-compose.yaml down || true # Clean up old images (optional) echo "๐Ÿงน Cleaning up old images..." docker image prune -f || true # Build new images echo "๐Ÿ—๏ธ Building new images..." docker compose --env-file docker/.env -f docker/docker-compose.yaml build # Start infrastructure first echo "๐Ÿš€ Starting infrastructure..." docker compose --env-file docker/.env -f docker/docker-compose.yaml up -d # Wait for infrastructure to be ready echo "โณ Waiting for infrastructure..." sleep 30 # Start services echo "๐Ÿš€ Starting services..." # Start services (already included in main compose file) docker compose --env-file docker/.env -f docker/docker-compose.yaml up -d # Wait for services to be ready echo "โณ Waiting for services..." sleep 30 # Start clients echo "๐Ÿš€ Starting clients..." # Start clients (already included in main compose file) docker compose --env-file docker/.env -f docker/docker-compose.yaml up -d # Health check echo "๐Ÿฅ Running health checks..." sleep 60 # Check service status echo "๐Ÿ“Š Service Status:" docker compose --env-file docker/.env -f docker/docker-compose.yaml ps # Check logs for errors echo "๐Ÿ“‹ Recent logs:" docker compose --env-file docker/.env -f docker/docker-compose.yaml logs --tail=50 echo "โœ… Deployment completed successfully!" ENDSSH - name: Verify Deployment env: PROXMOX_HOST: ${{ secrets.PROXMOX_HOST }} PROXMOX_USER: ${{ secrets.PROXMOX_USER }} run: | echo "๐Ÿ” Verifying deployment..." # Check if services are responding ssh $PROXMOX_USER@$PROXMOX_HOST << 'ENDSSH' # Check API Gateway health curl -f http://localhost:8081/actuator/health || echo "โŒ API Gateway health check failed" # Check Consul curl -f http://localhost:8500/v1/status/leader || echo "โŒ Consul health check failed" # Check Web-App curl -f http://localhost:4000/health || echo "โŒ Web-App health check failed" # Check VNC curl -f http://localhost:6080/ || echo "โŒ VNC health check failed" echo "โœ… Health checks completed" ENDSSH # =================================================================== # Notification (Optional) # =================================================================== notify: needs: [build-and-test, deploy] runs-on: ubuntu-latest if: always() steps: - name: Notify Success if: needs.deploy.result == 'success' run: | echo "โœ… Deployment to Proxmox successful!" echo "๐ŸŒ Web-App: https://meldestelle.yourdomain.com" echo "๐Ÿ–ฅ๏ธ Desktop-VNC: https://vnc.meldestelle.yourdomain.com" echo "๐Ÿ”— API: https://api.meldestelle.yourdomain.com" - name: Notify Failure if: needs.deploy.result == 'failure' run: | echo "โŒ Deployment to Proxmox failed!" echo "Check the logs above for details."