A production-grade CI/CD pipeline implementation using Python 3.12, Docker Compose, and Ansible with comprehensive testing, security scanning, and multi-environment deployment support.
- Python 3.12.5 (latest stable) with modern async/await patterns and type hints
- Docker Compose for consistent environment management
- Multi-environment support (dev, test, staging, prod) with PATH-scoped configurations
- Comprehensive CI/CD with GitHub Actions, GitLab CI, and Jenkins support
- Infrastructure as Code using Ansible 10.5.0 (latest stable)
- Security-first approach with automated scanning and policy enforcement
- Enterprise-grade monitoring with Prometheus, Grafana, and distributed tracing
- Automated testing including unit, integration, E2E, and performance tests
- Blue-green and rolling deployments with automatic rollback capabilities
- Docker Engine 27.2.0+ and Docker Compose v2.29.2+
- Python 3.12.5
- Ansible 10.5.0 (ansible-core 2.17.5)
- Make (for automation)
- Git
enterprise-app/
βββ src/ # Application source code
β βββ api/ # FastAPI application
β βββ core/ # Core business logic
β βββ utils/ # Utility functions
βββ tests/ # Test suites
β βββ unit/ # Unit tests
β βββ integration/ # Integration tests
β βββ e2e/ # End-to-end tests
β βββ performance/ # Performance tests
βββ docker/ # Docker configurations
β βββ dev/ # Development environment
β βββ test/ # Test environment
β βββ prod/ # Production environment
βββ environments/ # Environment-specific configs
β βββ dev/ # Development configs with PATH scoping
β βββ test/ # Test configs
β βββ prod/ # Production configs
βββ ansible/ # Ansible automation
β βββ playbooks/ # Deployment playbooks
β βββ inventories/ # Environment inventories
β βββ roles/ # Reusable roles
βββ ci-cd/ # CI/CD configurations
β βββ github-actions/ # GitHub Actions workflows
β βββ gitlab-ci/ # GitLab CI templates
βββ monitoring/ # Monitoring configurations
βββ prometheus/ # Prometheus configs
βββ grafana/ # Grafana dashboards
git clone https://github.com/your-org/enterprise-app.git
cd enterprise-app
# Copy environment templates
cp environments/dev/.env.example environments/dev/.env.local
# Load environment (with PATH scoping)
source scripts/env-loader.sh dev
# Using Make
make dev-up
# Or using Docker Compose directly
docker compose -f docker-compose.base.yml -f docker-compose.dev.yml up -d
# Run all tests
make test
# Run specific test suites
make test ENVIRONMENT=test
docker compose -f docker-compose.pipeline.yml run --rm pipeline-executor test
Environment-specific configurations are stored in environments/{env}/.env
files with PATH scoping support:
# Load environment with PATH scoping
source scripts/env-loader.sh [dev|test|staging|prod]
# This sets:
# - PATH to include environment-specific binaries
# - PYTHONPATH for environment-specific modules
# - Environment-specific tool configurations
Each environment has its own Docker Compose configuration:
docker-compose.dev.yml
- Development with hot-reload and debug toolsdocker-compose.test.yml
- Testing with isolated databasesdocker-compose.prod.yml
- Production with security and monitoring
The pipeline uses Docker Compose to run CI/CD jobs consistently:
# Start CI/CD infrastructure
make setup
# Run pipeline stages
make pipeline ENVIRONMENT=test
- Code Quality - Linting, formatting, type checking
- Security Scanning - Dependency scanning, SAST, container scanning
- Testing - Unit, integration, and E2E tests
- Build - Multi-stage Docker builds
- Deploy - Environment-specific deployment with Ansible
name: CI/CD Pipeline
on: [push, pull_request]
jobs:
test:
runs-on: [self-hosted, docker]
steps:
- uses: actions/checkout@v4
- run: make test
stages:
- test
- build
- deploy
test:
stage: test
script:
- make test
- Bandit - Python AST security scanner
- Safety - Dependency vulnerability scanner
- Trivy - Container vulnerability scanner
- SonarQube - Code quality and security analysis
# Install pre-commit hooks
pre-commit install
# Run manually
pre-commit run --all-files
# Deploy to development
make deploy ENVIRONMENT=dev
# Deploy to production (requires confirmation)
environments/prod/bin/deploy --confirm-production
# Deploy with Ansible
ansible-playbook -i ansible/inventories/prod/hosts.yml \
ansible/playbooks/deploy.yml \
-e "app_version=v1.0.0" \
-e "environment=production"
# Rollback to previous version
ansible-playbook -i ansible/inventories/prod/hosts.yml \
ansible/playbooks/rollback.yml \
-e "rollback_version=v0.9.0" \
-e "environment=production"
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000
- Jaeger: http://localhost:16686
# Check application health
curl http://localhost:8000/health
# Check metrics
curl http://localhost:8000/metrics
# Unit tests
pytest tests/unit -v
# Integration tests
pytest tests/integration -v
# End-to-end tests
pytest tests/e2e -v
# Performance tests
docker run --rm -v ./tests/performance:/scripts \
grafana/k6:latest run /scripts/load-test.js
# Generate coverage report
pytest --cov=src --cov-report=html
# View report
open htmlcov/index.html
# Install dependencies
pip install -e ".[dev]"
# Run application locally
uvicorn src.api.main:app --reload
# Run with Docker
docker compose -f docker-compose.dev.yml up
# Format code
black src tests
# Lint code
ruff check src tests
# Type checking
mypy src
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
# Build documentation
mkdocs build
# Serve locally
mkdocs serve
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit changes (
git commit -m 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with modern Python 3.12.5 features
- Uses latest Ansible 10.5.0 for infrastructure automation
- Implements enterprise best practices for CI/CD
- Docker Compose for consistent environments across all stages
- Documentation: docs/
- Issues: GitHub Issues
- Email: support@example.com
- Slack: #enterprise-app
Note: This is a reference implementation demonstrating enterprise-grade CI/CD practices. Adapt the configuration to match your specific requirements and infrastructure.