#!/bin/bash # Test Pipeline Prerequisites # Prüft alle Voraussetzungen für CI/CD Pipeline Tests set -euo pipefail echo "==========================================" echo "CI/CD Pipeline Prerequisites Check" echo "==========================================" echo "" ERRORS=0 WARNINGS=0 # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color check_pass() { echo -e "${GREEN}✓${NC} $1" } check_fail() { echo -e "${RED}✗${NC} $1" ((ERRORS++)) } check_warn() { echo -e "${YELLOW}⚠${NC} $1" ((WARNINGS++)) } # 1. Check Gitea Runner echo "1. Checking Gitea Runner..." if [ -d "deployment/gitea-runner" ]; then cd deployment/gitea-runner if docker compose ps 2>/dev/null | grep -q "gitea-runner.*Up"; then check_pass "Gitea Runner container is running" else check_fail "Gitea Runner container is not running" echo " Run: cd deployment/gitea-runner && docker compose up -d" fi if docker compose ps 2>/dev/null | grep -q "gitea-runner-dind.*Up"; then check_pass "Gitea Runner DinD container is running" else check_fail "Gitea Runner DinD container is not running" fi if [ -f "data/.runner" ]; then check_pass "Gitea Runner is registered (data/.runner exists)" else check_warn "Gitea Runner may not be registered (data/.runner missing)" echo " Run: ./register.sh" fi cd - > /dev/null else check_fail "deployment/gitea-runner directory not found" fi echo "" # 2. Check Workflow Files echo "2. Checking Workflow Files..." if [ -f ".gitea/workflows/build-image.yml" ]; then check_pass "build-image.yml workflow exists" else check_fail ".gitea/workflows/build-image.yml not found" fi if [ -f ".gitea/workflows/manual-deploy.yml" ]; then check_pass "manual-deploy.yml workflow exists" else check_warn ".gitea/workflows/manual-deploy.yml not found (optional)" fi echo "" # 3. Check Ansible Playbooks echo "3. Checking Ansible Playbooks..." ANSIBLE_PLAYBOOKS=( "deployment/ansible/playbooks/deploy-application-code.yml" "deployment/ansible/playbooks/install-composer-dependencies.yml" "deployment/ansible/playbooks/deploy-image.yml" "deployment/ansible/playbooks/backup.yml" ) for playbook in "${ANSIBLE_PLAYBOOKS[@]}"; do if [ -f "$playbook" ]; then check_pass "$(basename $playbook) exists" else check_fail "$playbook not found" fi done echo "" # 4. Check Ansible Inventory echo "4. Checking Ansible Inventory..." if [ -f "deployment/ansible/inventory/production.yml" ]; then check_pass "Ansible inventory file exists" else check_fail "deployment/ansible/inventory/production.yml not found" fi echo "" # 5. Check Docker Compose Files echo "5. Checking Docker Compose Files..." if [ -f "deployment/stacks/production/docker-compose.base.yml" ]; then check_pass "Production docker-compose.base.yml exists" else check_fail "Production docker-compose.base.yml not found" fi if [ -f "deployment/stacks/production/docker-compose.production.yml" ]; then check_pass "Production docker-compose.production.yml exists" else check_fail "Production docker-compose.production.yml not found" fi if [ -f "deployment/stacks/staging/docker-compose.base.yml" ]; then check_pass "Staging docker-compose.base.yml exists" else check_warn "Staging docker-compose.base.yml not found (optional for staging tests)" fi echo "" # 6. Check Dockerfile echo "6. Checking Dockerfile..." if [ -f "Dockerfile.production" ]; then check_pass "Dockerfile.production exists" else check_fail "Dockerfile.production not found" fi echo "" # 7. Check SSH Key (if exists locally) echo "7. Checking SSH Configuration..." if [ -f "$HOME/.ssh/production" ] || [ -f "$HOME/.ssh/id_rsa" ] || [ -f "$HOME/.ssh/id_ed25519" ]; then check_pass "SSH key found (local check only)" echo " Note: SSH_PRIVATE_KEY secret must be configured in Gitea" else check_warn "No SSH key found locally (may be configured in Gitea secrets)" fi echo "" # 8. Check Registry Access (if possible) echo "8. Checking Docker Registry Access..." REGISTRY="registry.michaelschiemer.de" if command -v curl >/dev/null 2>&1; then if curl -s -k --connect-timeout 5 "https://${REGISTRY}/v2/" >/dev/null 2>&1 || \ curl -s --connect-timeout 5 "http://94.16.110.151:5000/v2/" >/dev/null 2>&1; then check_pass "Docker Registry is accessible" else check_warn "Docker Registry may not be accessible (check network/firewall)" fi else check_warn "curl not available, skipping registry check" fi echo "" # 9. Check Git Repository echo "9. Checking Git Repository..." if git remote get-url origin 2>/dev/null | grep -q "git.michaelschiemer.de"; then check_pass "Git remote points to Gitea" REMOTE_URL=$(git remote get-url origin 2>/dev/null || echo "") echo " Remote: $REMOTE_URL" else check_warn "Git remote may not point to Gitea" REMOTE_URL=$(git remote get-url origin 2>/dev/null || echo "not configured") echo " Remote: $REMOTE_URL" fi # Check for staging and main branches if git show-ref --verify --quiet refs/heads/staging 2>/dev/null; then check_pass "staging branch exists locally" else check_warn "staging branch not found locally (may need to fetch)" fi if git show-ref --verify --quiet refs/heads/main 2>/dev/null; then check_pass "main branch exists locally" else check_warn "main branch not found locally (may need to fetch)" fi echo "" # Summary echo "==========================================" echo "Summary" echo "==========================================" if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then echo -e "${GREEN}✓ All checks passed!${NC}" echo "" echo "Next steps:" echo "1. Verify Gitea Secrets are configured:" echo " https://git.michaelschiemer.de/michael/michaelschiemer/settings/secrets/actions" echo "" echo "2. Test Staging Pipeline:" echo " git checkout staging" echo " echo '# Test' >> README.md" echo " git commit -m 'test: CI/CD pipeline'" echo " git push origin staging" echo "" echo "3. Monitor Pipeline:" echo " https://git.michaelschiemer.de/michael/michaelschiemer/actions" exit 0 elif [ $ERRORS -eq 0 ]; then echo -e "${YELLOW}⚠ Checks passed with warnings${NC}" echo " Warnings: $WARNINGS" echo "" echo "Review warnings above and proceed with testing." exit 0 else echo -e "${RED}✗ Checks failed${NC}" echo " Errors: $ERRORS" echo " Warnings: $WARNINGS" echo "" echo "Please fix the errors above before testing the pipeline." exit 1 fi