197 lines
6.1 KiB
YAML
197 lines
6.1 KiB
YAML
# ===================================================================
|
|
# 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 25
|
|
uses: actions/setup-java@v5
|
|
with:
|
|
java-version: '25'
|
|
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."
|