Skip to content

nirgeier/DevOps-Demo-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DevOps Demo Project πŸš€

A complete DevOps CI/CD pipeline demonstration project featuring Python Flask application, Docker containerization, Kubernetes deployment with Helm, ArgoCD GitOps, and automated GitHub Actions workflows.

DevOps Pipeline Python Docker Kubernetes License

πŸ“‹ Table of Contents

🎯 Overview

This project demonstrates a modern DevOps workflow implementing:

  • Python Flask Application: RESTful API with health checks
  • Container Orchestration: Docker multi-stage builds
  • Kubernetes Deployment: Helm charts with best practices
  • GitOps: ArgoCD for automated deployments
  • CI/CD: GitHub Actions for build, test, and deploy
  • GitFlow: Branch-based development workflow
  • Automated Testing: Unit tests with pytest and coverage

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Git Repo  β”‚
β”‚  (GitHub)   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ GitHub Actions  β”‚  ← CI/CD Pipeline
β”‚  - Build        β”‚
β”‚  - Test         β”‚
β”‚  - Push Image   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ GitHub Registry β”‚  ← Container Storage
β”‚     (GHCR)      β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    ArgoCD       β”‚  ← GitOps Controller
β”‚ (Kubernetes)    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Kubernetes    β”‚  ← Production Environment
β”‚   with Helm     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

Application Features

  • βœ… RESTful API endpoints
  • βœ… Health and readiness probes
  • βœ… Structured logging
  • βœ… Error handling
  • βœ… Environment-based configuration

DevOps Features

  • βœ… Multi-stage Docker builds
  • βœ… Kubernetes-ready Helm charts
  • βœ… Horizontal Pod Autoscaling (HPA)
  • βœ… ArgoCD GitOps deployment
  • βœ… Automated CI/CD with GitHub Actions
  • βœ… GitFlow workflow enforcement with Git hooks
  • βœ… Automated testing and code coverage
  • βœ… Container image signing and attestation
  • βœ… GitHub Copilot integration in Git hooks

πŸ“¦ Prerequisites

  • Python 3.11+
  • Docker (install manually from https://docs.docker.com/get-docker/)
  • kubectl (for Kubernetes)
  • Helm (for Kubernetes package management)
  • uv (Python package manager)
  • k9s (optional, for Kubernetes cluster management)

Automated Installation

Run the init script to install all required tools:

chmod +x scripts/init.sh
./scripts/init.sh

Git Hooks Setup

Configure Git hooks for GitFlow enforcement:

chmod +x .githooks/setup.sh
./.githooks/setup.sh

Or install tools individually:

chmod +x scripts/*.sh
./scripts/install-uv.sh
./scripts/install-kubectl.sh
./scripts/install-helm.sh
./scripts/install-k9s.sh
./scripts/install-argocd.sh  # Optional

πŸš€ Quick Start

1. Clone and Initialize

git clone https://github.com/nirgeier/DevOps-Demo-Project.git
cd DevOps-Demo-Project
./scripts/init.sh

2. Run Locally

# Activate virtual environment
source .venv/bin/activate

# Run the application
python app/main.py

# Or with gunicorn (production-like)
gunicorn --bind 0.0.0.0:8080 app.main:app

Visit: http://localhost:8080

3. Run with Docker

# Build the image
docker build -f docker/Dockerfile -t ghcr.io/nirgeier/devops-demo-project:latest .

# Run the container
docker run -p 8080:8080 ghcr.io/nirgeier/devops-demo-project:latest

# Or use docker-compose
docker-compose -f docker/docker-compose.yml up -d

4. Build Helm Chart

Validate and package the Helm chart for Kubernetes deployment:

# Lint the Helm chart for errors
helm lint helm/devops-demo

# Template the chart to see generated Kubernetes manifests
helm template devops-demo helm/devops-demo

# Package the chart into a .tgz file
helm package helm/devops-demo

# Validate the packaged chart
helm lint devops-demo-*.tgz

# Uninstall previous release if exists
helm uninstall devops-demo-test --namespace devops-demo || true

# Test the chart installation (dry-run)
helm install devops-demo-test helm/devops-demo --namespace devops-demo --create-namespace 

# Clean up test package
rm devops-demo-*.tgz

Helm Chart Details:

Property Description
Chart Name devops-demo
Version Defined in helm/devops-demo/Chart.yaml
Values Configurable via helm/devops-demo/values.yaml
Templates Kubernetes manifests in helm/devops-demo/templates/

Common Helm Commands:

# List all releases
helm list -A

# Get release status
helm status devops-demo

# Upgrade release
helm upgrade devops-demo helm/devops-demo --namespace devops-demo 

# Rollback release
helm rollback devops-demo --namespace devops-demo

# Uninstall release
helm uninstall devops-demo --namespace devops-demo

5. Deploy to Kubernetes

# Install with Helm, updating or installing as needed
helm upgrade                                     \
       --install devops-demo helm/devops-demo    \
       --namespace devops-demo                    \
       --create-namespace                        \
       --values helm/devops-demo/values.yaml

# Or use ArgoCD
kubectl apply -f argocd/namespace.yaml
kubectl apply -f argocd/application.yaml

πŸ“ Project Structure

DevOps-Demo-Project/
β”œβ”€β”€ app/                      # Python application
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── main.py              # Flask application
β”œβ”€β”€ tests/                    # Test suite
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── test_main.py         # Unit tests
β”œβ”€β”€ docker/                   # Docker configuration
β”‚   β”œβ”€β”€ Dockerfile           # Multi-stage build
β”‚   β”œβ”€β”€ .dockerignore
β”‚   └── docker-compose.yml
β”œβ”€β”€ helm/                     # Helm charts
β”‚   └── devops-demo/
β”‚       β”œβ”€β”€ Chart.yaml
β”‚       β”œβ”€β”€ values.yaml
β”‚       └── templates/       # Kubernetes manifests
β”œβ”€β”€ argocd/                   # ArgoCD configuration
β”‚   β”œβ”€β”€ application.yaml
β”‚   β”œβ”€β”€ namespace.yaml
β”‚   └── README.md
β”œβ”€β”€ scripts/                  # Installation scripts
β”‚   β”œβ”€β”€ init.sh              # Project initialization
β”‚   β”œβ”€β”€ install-uv.sh
β”‚   β”œβ”€β”€ install-kubectl.sh
β”‚   β”œβ”€β”€ install-helm.sh
β”‚   └── install-k9s.sh
β”œβ”€β”€ .githooks/                # Git hooks for GitFlow
β”‚   β”œβ”€β”€ pre-commit           # Branch protection & checks
β”‚   β”œβ”€β”€ commit-msg           # Commit message validation
β”‚   β”œβ”€β”€ pre-push             # Branch naming validation
β”‚   β”œβ”€β”€ setup.sh             # Hooks installation script
β”‚   └── README.md            # Hooks documentation
β”‚   └── workflows/
β”‚       β”œβ”€β”€ ci.yml           # Continuous Integration
β”‚       β”œβ”€β”€ cd.yml           # Continuous Deployment
β”‚       β”œβ”€β”€ release.yml      # Release management
β”‚       └── gitflow.yml      # GitFlow validation
β”œβ”€β”€ docs/                     # Documentation
β”œβ”€β”€ pyproject.toml           # Python dependencies
β”œβ”€β”€ .gitignore
└── README.md

πŸ’» Development

Running Tests

# Run all tests
pytest tests/ -v

# With coverage report
pytest tests/ -v --cov=app --cov-report=html

# View coverage report
open htmlcov/index.html

Code Quality

# Linting
flake8 app/ tests/

# Formatting
black app/ tests/

Local Development

# Create virtual environment
uv venv

# Activate environment
source .venv/bin/activate

# Install dependencies
uv pip install -e ".[dev]"

# Run development server
python app/main.py

🚒 Deployment

Docker Deployment

# Build multi-platform image
docker buildx build --platform linux/amd64,linux/arm64 \
  -f docker/Dockerfile \
  -t ghcr.io/nirgeier/devops-demo-project:latest \
  --push .

Kubernetes Deployment

# Using Helm
helm upgrade --install devops-demo helm/devops-demo \
  --namespace devops-demo \
  --create-namespace \
  --values helm/devops-demo/values.yaml

# Check deployment
kubectl get pods -n devops-demo
kubectl get svc -n devops-demo

# Port forward for local access
kubectl port-forward -n devops-demo svc/devops-demo 8080:80

ArgoCD Deployment

# Install ArgoCD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

# Deploy application
kubectl apply -f argocd/namespace.yaml
kubectl apply -f argocd/application.yaml

# Access ArgoCD UI
kubectl port-forward svc/argocd-server -n argocd 8080:443

πŸ”„ GitFlow Workflow

This project follows the GitFlow branching model:

Branch Structure

  • main - Production-ready code
  • develop - Integration branch for features
  • feature/* - New features (branch from develop)
  • release/* - Release preparation (branch from develop)
  • hotfix/* - Production fixes (branch from main)

Workflow

  1. Feature Development

    git checkout develop
    git checkout -b feature/new-feature
    # ... make changes ...
    git push origin feature/new-feature
    # Create PR to develop
  2. Release Process

    git checkout develop
    git checkout -b release/1.0.0
    # ... update version, changelog ...
    git push origin release/1.0.0
    # Create PR to main
  3. Hotfix

    git checkout main
    git checkout -b hotfix/critical-fix
    # ... fix issue ...
    git push origin hotfix/critical-fix
    # Create PR to main

πŸ”§ CI/CD Pipeline

Continuous Integration (CI)

Triggered on: Push to any branch, Pull Requests

Steps:

  1. βœ… Code checkout
  2. βœ… Python setup with uv
  3. βœ… Install dependencies
  4. βœ… Run linting (flake8)
  5. βœ… Run tests with coverage
  6. βœ… Build Docker image
  7. βœ… Test Docker image

Continuous Deployment (CD)

Triggered on: Push to main, Version tags

Steps:

  1. βœ… Build multi-platform Docker image
  2. βœ… Push to GitHub Container Registry
  3. βœ… Generate image attestation
  4. βœ… Create GitHub release (for tags)
  5. βœ… Update GitOps repository

Release Management

Automated release workflow:

  1. Create release branch
  2. Automatic PR to main
  3. On merge: Create version tag
  4. Trigger CD pipeline
  5. Merge back to develop

πŸ“š Documentation

πŸ”— API Endpoints

Endpoint Method Description
/ GET Welcome message
/health GET Health check
/ready GET Readiness probe
/api/info GET Application information
/api/echo POST Echo endpoint

πŸ› οΈ Tools Used

  • Python/Flask - Application framework
  • uv - Fast Python package manager
  • Docker - Containerization
  • Kubernetes - Container orchestration
  • Helm - Kubernetes package manager
  • ArgoCD - GitOps continuous delivery
  • GitHub Actions - CI/CD automation
  • pytest - Testing framework
  • k9s - Kubernetes CLI manager

πŸ“„ License

MIT License - see LICENSE file for details

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“§ Contact

For questions or support, please open an issue on GitHub.


Made with ❀️ for DevOps Engineers DevOps-Demo-Project

About

DevOps-Demo-Project

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors