steps: # Validate all compose files have valid syntax validate: image: docker:latest commands: - docker-compose config -f git.yaml > /dev/null - echo "✓ git.yaml syntax valid" volumes: - /var/run/docker.sock:/var/run/docker.sock when: branch: main # Deploy to Docker Swarm deploy: image: alpine:latest commands: - apk add --no-cache openssh-client - mkdir -p ~/.ssh - echo "$SSH_KEY" | base64 -d > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan -H docker-2.local >> ~/.ssh/known_hosts 2>/dev/null || true # Copy compose files to swarm manager - scp -o StrictHostKeyChecking=no -r *.yaml root@docker-2.local:/tmp/compose/ - scp -o StrictHostKeyChecking=no *.env root@docker-2.local:/tmp/compose/ || true # Deploy stacks via SSH - | ssh -o StrictHostKeyChecking=no root@docker-2.local << 'DEPLOY' cd /tmp/compose docker stack deploy -c git.yaml git echo "✓ Git stack deployed" DEPLOY secrets: - ssh_key when: branch: main event: push # Verify deployment success verify: image: alpine:latest commands: - apk add --no-cache openssh-client - mkdir -p ~/.ssh - echo "$SSH_KEY" | base64 -d > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan -H docker-2.local >> ~/.ssh/known_hosts 2>/dev/null || true # Check stack status - | ssh -o StrictHostKeyChecking=no root@docker-2.local << 'VERIFY' echo "Git Stack Status:" docker stack ps git VERIFY secrets: - ssh_key when: branch: main status: success # Notify Teams on success notify-success: image: alpine:latest commands: - apk add --no-cache curl - | curl -X POST -H 'Content-Type: application/json' \ -d '{ "title": "✅ Compose Deploy Success", "text": "homelab/compose-files deployed to Docker Swarm", "themeColor": "00aa00" }' \ "$TEAMS_WEBHOOK" secrets: - teams_webhook when: branch: main status: success # Notify Teams on failure notify-failure: image: alpine:latest commands: - apk add --no-cache curl - | curl -X POST -H 'Content-Type: application/json' \ -d '{ "title": "❌ Compose Deploy Failed", "text": "homelab/compose-files deployment failed", "themeColor": "ff0000" }' \ "$TEAMS_WEBHOOK" secrets: - teams_webhook when: branch: main status: failure