Skip to content

aatirFound42/python-cicd-4localServers-withTools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Python CI/CD App - Complete DevOps Pipeline

Production-ready Flask app with complete GitHub Actions CI/CD pipeline using self-hosted runner!

✨ Features

  • πŸ”„ 6-Stage CI/CD Pipeline: Build β†’ Test β†’ Quality β†’ Reports β†’ Notify β†’ Deploy
  • πŸ–₯️ Self-Hosted Runner: Direct Docker deployment to production VM
  • πŸ§ͺ Multi-Python Testing: Python 3.9, 3.10, 3.11 matrix
  • πŸ“Š 85% Code Coverage requirement with HTML dashboards
  • πŸ›‘οΈ Security Scanning: Bandit + Secret Detection
  • πŸ“ˆ Zero-Downtime Deployments with health checks & rollback
  • 🎨 Production Reports: Interactive coverage dashboards

πŸ—οΈ Tech Stack

Backend: Flask (Python 3.9+)
CI/CD: GitHub Actions + Self-Hosted Runner
Container: Docker + GHCR
Testing: pytest + pytest-cov (85% coverage)
Linting: flake8 + pylint
Security: Bandit + detect-secrets
Deployment: Direct Docker (no SSH!)

πŸš€ Quick Start

1. Clone & Install

git clone https://github.com/aatirFound42/python-cicd-app.git
cd python-cicd-app
pip install -r requirements.txt

2. Run Locally

# Development
flask run

# Production mode
FLASK_ENV=production flask run --host=0.0.0.0 --port=5000

3. Docker

# Build
docker build -t python-cicd-app .

# Run
docker run -p 8000:5000 python-cicd-app

Access: http://localhost:8000

πŸ”„ CI/CD Pipeline

6 Production Stages:

Stage Runner Purpose
Build ubuntu-latest Docker image β†’ GHCR
Test ubuntu-latest pytest matrix 3.9-3.11
Quality ubuntu-latest 85% coverage gate
Reports ubuntu-latest HTML dashboards
Deploy self-hosted πŸš€ Production VM

Pipeline Flow:

develop β†’ Tests β†’ Quality Gates β†’ Coverage Reports
     ↓ (main + approve)
main β†’ Build β†’ Deploy to VM:8000 β†’ Health Check βœ“

πŸ–₯️ Self-Hosted Runner Setup

VM Requirements:

Ubuntu 20.04+ / Docker 20+
GitHub Runner v2.330.0
Port 8000 open

Runner Install:

# On production VM
sudo apt install docker.io
sudo useradd -m -G docker runner
sudo su - runner
mkdir actions-runner && cd actions-runner
curl -o actions-runner-linux-x64-2.330.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.330.0/actions-runner-linux-x64-2.330.0.tar.gz
tar xzf ./actions-runner-linux-x64-2.330.0.tar.gz
./config.sh --url https://github.com/aatirFound42/python-cicd-app --token YOUR_TOKEN
./run.sh  # Keep running!

πŸ” Environment Secrets

Repo β†’ Settings β†’ Environments β†’ production:

CONTAINER_NAME=python-cicd-app-prod
CONTAINER_PORT_HOST=8000

πŸ“Š Quality Gates

βœ… 85% Code Coverage (3 Python versions)
βœ… Linting: flake8 + pylint  
βœ… Security: Bandit scan
βœ… Secrets: detect-secrets
βœ… Multi-stage testing
βœ… Health check deployment

🌐 Production Access

VM Local: http://localhost:8000
Network: http://YOUR_VM_IP:8000
Internet: http://PUBLIC_IP:8000 (port forward 8000)

πŸ“ Project Structure

python-cicd-app/
β”œβ”€β”€ app/                 # Flask application
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── routes.py
β”œβ”€β”€ tests/               # pytest tests
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ Dockerfile          # Production Docker image
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── python-cicd.yml  # Complete pipeline
β”œβ”€β”€ docker-compose.yml  # Local development
└── README.md          # This file!

πŸ§ͺ Running Tests Locally

# Install test deps
pip install -r requirements.txt pytest pytest-cov

# Run tests + coverage
pytest tests/ --cov=app --cov-report=html

# View coverage
open htmlcov/index.html

πŸ”§ Development Workflow

1. git checkout -b feature/xyz
2. code β†’ commit β†’ push
3. Tests run automatically (develop)
4. Merge develop β†’ main (production deploy)
5. VM auto-deploys: docker pull β†’ docker run

πŸ“ˆ Coverage Reports

After pipeline runs:

Actions β†’ Artifacts β†’ all-coverage-reports
β†’ Interactive HTML dashboards for 3 Python versions

βš™οΈ Dockerfile Highlights

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
HEALTHCHECK --interval=30s CMD curl -f http://localhost:5000/health
CMD ["gunicorn", "app:app", "-b", "0.0.0.0:5000"]

🎯 Why This Pipeline Rocks

βœ… Self-hosted = FREE unlimited minutes
βœ… No SSH complexity
βœ… Automatic rollbacks
βœ… Multi-environment testing
βœ… Production dashboards
βœ… Zero-downtime deploys
βœ… Scalable to teams

🀝 Contributing

  1. Fork repository
  2. Create feature branch (git checkout -b feature/xyz)
  3. Commit changes (git commit -m "Add feature")
  4. Push (git push origin feature/xyz)
  5. Open Pull Request

All PRs run full CI/CD pipeline automatically!

πŸ“„ License

MIT License - Free to use & modify!


⭐ Star this repo if you found the self-hosted CI/CD setup helpful!

Pipeline | Docker Hub

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors