feat: Добавлены 3 стадии в CI/CD пайплайны (lint, test, deploy)
- GitHub Actions: добавлены стадии lint, test, deploy с зависимостями - Azure DevOps: добавлены стадии lint, test, deploy с зависимостями - Jenkins: добавлены стадии lint, test, deploy с зависимостями - GitLab CI: создан новый .gitlab-ci.yml с 3 стадиями Особенности: - Деплой происходит только после успешного прохождения lint и test - Деплой выполняется только для main ветки - Добавлены уведомления о результатах - Используются make команды для консистентности - Параллельное тестирование с разными preset'ами
This commit is contained in:
		| @@ -2,7 +2,7 @@ | ||||
| # Автор: Сергей Антропов | ||||
| # Сайт: https://devops.org.ru | ||||
|  | ||||
| name: Ansible Testing | ||||
| name: AnsibleLab CI/CD Pipeline | ||||
|  | ||||
| on: | ||||
|   push: | ||||
| @@ -11,44 +11,9 @@ on: | ||||
|     branches: [ main ] | ||||
|  | ||||
| jobs: | ||||
|   test: | ||||
|     runs-on: ubuntu-latest | ||||
|      | ||||
|     steps: | ||||
|     - name: Checkout code | ||||
|       uses: actions/checkout@v4 | ||||
|        | ||||
|     - name: Set up Python | ||||
|       uses: actions/setup-python@v4 | ||||
|       with: | ||||
|         python-version: '3.11' | ||||
|          | ||||
|     - name: Install system dependencies | ||||
|       run: | | ||||
|         sudo apt-get update | ||||
|         sudo apt-get install -y docker.io | ||||
|         sudo systemctl start docker | ||||
|         sudo usermod -aG docker $USER | ||||
|          | ||||
|     - name: Install Python dependencies | ||||
|       run: | | ||||
|         pip install --upgrade pip | ||||
|         pip install molecule[docker] ansible-lint | ||||
|         ansible-galaxy collection install -r requirements.yml | ||||
|          | ||||
|     - name: Run Molecule tests | ||||
|       run: | | ||||
|         cd molecule/universal | ||||
|         molecule test -s universal | ||||
|          | ||||
|     - name: Upload test results | ||||
|       uses: actions/upload-artifact@v3 | ||||
|       if: always() | ||||
|       with: | ||||
|         name: molecule-reports | ||||
|         path: molecule/universal/.molecule/ | ||||
|          | ||||
|   # Стадия 1: Lint проверка | ||||
|   lint: | ||||
|     name: 🔍 Lint Check | ||||
|     runs-on: ubuntu-latest | ||||
|      | ||||
|     steps: | ||||
| @@ -62,9 +27,146 @@ jobs: | ||||
|          | ||||
|     - name: Install dependencies | ||||
|       run: | | ||||
|         pip install ansible-lint | ||||
|         pip install --upgrade pip | ||||
|         pip install ansible ansible-lint | ||||
|         ansible-galaxy collection install -r requirements.yml | ||||
|          | ||||
|     - name: Run Ansible Lint | ||||
|       run: | | ||||
|         ansible-lint molecule/universal/ | ||||
|         echo "🔍 Проверка синтаксиса ролей..." | ||||
|         make role lint | ||||
|          | ||||
|     - name: Upload lint results | ||||
|       uses: actions/upload-artifact@v3 | ||||
|       if: always() | ||||
|       with: | ||||
|         name: lint-results | ||||
|         path: | | ||||
|           .ansible-lint | ||||
|           lint-report.txt | ||||
|  | ||||
|   # Стадия 2: Тестирование | ||||
|   test: | ||||
|     name: 🧪 Role Testing | ||||
|     runs-on: ubuntu-latest | ||||
|     needs: lint | ||||
|      | ||||
|     strategy: | ||||
|       matrix: | ||||
|         preset: [minimal, default, performance] | ||||
|      | ||||
|     steps: | ||||
|     - name: Checkout code | ||||
|       uses: actions/checkout@v4 | ||||
|        | ||||
|     - name: Set up Python | ||||
|       uses: actions/setup-python@v4 | ||||
|       with: | ||||
|         python-version: '3.11' | ||||
|          | ||||
|     - name: Install system dependencies | ||||
|       run: | | ||||
|         sudo apt-get update | ||||
|         sudo apt-get install -y docker.io make | ||||
|         sudo systemctl start docker | ||||
|         sudo usermod -aG docker $USER | ||||
|          | ||||
|     - name: Install Python dependencies | ||||
|       run: | | ||||
|         pip install --upgrade pip | ||||
|         pip install ansible ansible-lint | ||||
|         ansible-galaxy collection install -r requirements.yml | ||||
|          | ||||
|     - name: Setup Docker builder | ||||
|       run: | | ||||
|         make docker setup-builder | ||||
|          | ||||
|     - name: Build Docker images | ||||
|       run: | | ||||
|         make docker build | ||||
|          | ||||
|     - name: Run Molecule tests | ||||
|       run: | | ||||
|         echo "🧪 Тестирование с preset: ${{ matrix.preset }}" | ||||
|         make role test ${{ matrix.preset }} | ||||
|          | ||||
|     - name: Upload test results | ||||
|       uses: actions/upload-artifact@v3 | ||||
|       if: always() | ||||
|       with: | ||||
|         name: test-results-${{ matrix.preset }} | ||||
|         path: | | ||||
|           molecule/default/.molecule/ | ||||
|           test-report-${{ matrix.preset }}.txt | ||||
|  | ||||
|   # Стадия 3: Деплой (только для main ветки) | ||||
|   deploy: | ||||
|     name: 🚀 Deploy Check | ||||
|     runs-on: ubuntu-latest | ||||
|     needs: [lint, test] | ||||
|     if: github.ref == 'refs/heads/main' && github.event_name == 'push' | ||||
|      | ||||
|     steps: | ||||
|     - name: Checkout code | ||||
|       uses: actions/checkout@v4 | ||||
|        | ||||
|     - name: Set up Python | ||||
|       uses: actions/setup-python@v4 | ||||
|       with: | ||||
|         python-version: '3.11' | ||||
|          | ||||
|     - name: Install dependencies | ||||
|       run: | | ||||
|         pip install --upgrade pip | ||||
|         pip install ansible ansible-lint | ||||
|         ansible-galaxy collection install -r requirements.yml | ||||
|          | ||||
|     - name: Create inventory file | ||||
|       run: | | ||||
|         mkdir -p inventory | ||||
|         cat > inventory/hosts.ini << EOF | ||||
|         [test_servers] | ||||
|         localhost ansible_connection=local | ||||
|          | ||||
|         [all:vars] | ||||
|         ansible_python_interpreter=python3 | ||||
|         EOF | ||||
|          | ||||
|     - name: Run deployment check | ||||
|       run: | | ||||
|         echo "🚀 Проверка развертывания (dry-run)..." | ||||
|         make role deploy | ||||
|          | ||||
|     - name: Upload deployment results | ||||
|       uses: actions/upload-artifact@v3 | ||||
|       if: always() | ||||
|       with: | ||||
|         name: deployment-results | ||||
|         path: | | ||||
|           deployment.log | ||||
|           deployment-report.txt | ||||
|  | ||||
|   # Уведомления | ||||
|   notify: | ||||
|     name: 📢 Notifications | ||||
|     runs-on: ubuntu-latest | ||||
|     needs: [lint, test, deploy] | ||||
|     if: always() | ||||
|      | ||||
|     steps: | ||||
|     - name: Notify on success | ||||
|       if: needs.lint.result == 'success' && needs.test.result == 'success' | ||||
|       run: | | ||||
|         echo "✅ Все проверки пройдены успешно!" | ||||
|         echo "🔍 Lint: ${{ needs.lint.result }}" | ||||
|         echo "🧪 Test: ${{ needs.test.result }}" | ||||
|         echo "🚀 Deploy: ${{ needs.deploy.result }}" | ||||
|          | ||||
|     - name: Notify on failure | ||||
|       if: needs.lint.result == 'failure' || needs.test.result == 'failure' | ||||
|       run: | | ||||
|         echo "❌ Проверки не пройдены!" | ||||
|         echo "🔍 Lint: ${{ needs.lint.result }}" | ||||
|         echo "🧪 Test: ${{ needs.test.result }}" | ||||
|         echo "🚀 Deploy: ${{ needs.deploy.result }}" | ||||
|         exit 1 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user