Files
DevOpsLab/cicd/github/workflows.yml
Сергей Антропов d8e1052e7b refactor: переименование проекта AnsibleLab -> DevOpsLab
- Заменено название проекта во всех файлах проекта
- Обновлены:
  * README.md
  * Makefile
  * Все файлы документации (.md)
  * CI/CD конфигурации (Jenkins, GitLab, GitHub Actions, Azure DevOps)
  * Скрипты (setup-cicd.sh, test-custom-images.sh)
  * Файлы конфигурации Molecule
- Изменена переменная PROJECT_NAME в Makefile на devops-lab
- Docker образы inecs/ansible-lab:* оставлены без изменений
  (чтобы не затрагивать существующие образы в Docker Hub)
2025-10-26 12:28:05 +03:00

173 lines
4.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# GitHub Actions Workflow для DevOpsLab
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
name: DevOpsLab CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
# Стадия 1: Lint проверка
lint:
name: 🔍 Lint Check
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 dependencies
run: |
pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml
- name: Run Ansible Lint
run: |
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