A comprehensive demonstration of a T-Shaped DevOps Solution, combining a broad automated CI/CD pipeline with a Deep Dive vertical in Automated Security (DevSecOps). This project implements a fully automated "Commit-to-Production" workflow for a Python FastAPI application.
- Project Overview
- Architecture & Pipeline
- Technologies & Tools
- Project Structure
- Deep Dive: Security (DevSecOps)
- CI/CD Pipeline Details
- Getting Started
- Deployment
- Future Improvements
This project replaces manual deployments with a robust DevSecOps pipeline that ensures consistency, security, and resilience.
- Microservices Architecture: Containerized FastAPI application.
- Infrastructure as Code (IaC): Terraform manages Kubernetes namespaces and resources.
- Shift-Left Security: Vulnerabilities are caught before build using SAST (Bandit).
- GitOps Delivery: Automated manifest updates trigger ArgoCD syncs (conceptually).
- Zero-Downtime: Kubernetes handles rolling updates and self-healing.
The solution follows a modern DevSecOps lifecycle, integrating security checks directly into the CI/CD flow.
graph TD
subgraph "Dev Workstation"
Dev[๐ฉโ๐ป Developer] -->|Git Push| GH[GitHub Repo]
end
subgraph "CI Pipeline (GitHub Actions)"
GH -->|Trigger| Bandit["๐ก๏ธ SAST Scan (Bandit)"]
Bandit -->|Pass| Docker[๐ณ Docker Build]
Docker -->|Push| Hub[โ๏ธ Docker Hub]
Hub -->|Scan| Trivy[๐ Trivy Image Scan]
end
subgraph "GitOps (CD)"
Hub -->|Update Tag| Manifest[๐ Deployment YAML]
Manifest -->|Commit| GitOps[Update Repo]
end
subgraph "Kubernetes Cluster"
GitOps -.->|Sync| ArgoCD[๐ ArgoCD]
ArgoCD -->|Apply| K8s[๐ Deployment]
K8s --> Service[๐ Service]
Service --> Pod[๐ฆ App Pods]
Ingress[๐ช Ingress] -->|Route| Service
end
style Bandit fill:#ffcccc,stroke:#333,color:black
style ArgoCD fill:#ccffcc,stroke:#333,color:black
style Docker fill:#ccf,stroke:#333,color:black
style Trivy fill:#ffcccc,stroke:#333,color:black
style Ingress fill:#e1d5e7,stroke:#333,color:black
.
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml # ๐ค The Automated Pipeline Definition
โโโ app/
โ โโโ main.py # ๐ FastAPI Source Code
โ โโโ Dockerfile # ๐ณ Container instructions
โโโ k8s/
โ โโโ deployment.yaml # โธ๏ธ Deployment Manifest (Auto-updated by CI)
โ โโโ service.yaml # โธ๏ธ Internal ClusterIP Service
โ โโโ ingress.yaml # ๐ช Ingress Routing Rules
โโโ terraform/
โ โโโ main.tf # ๐๏ธ IaC: Namespace provisioning
โ โโโ ...
โโโ README.md # ๐ This documentationThis project adopts a "Security First" approach by integrating Bandit (SAST) and Trivy (Container Security) into the pipeline.
Bandit is a tool designed to find common security issues in Python code. By running it before the Docker build step, we ensure that:
- Vulnerable code never reaches production.
- Feedback is immediate (the pipeline fails if issues are found).
What it checks:
- Hardcoded passwords/secrets.
- SQL injection risks.
- Unsafe parsing (e.g.,
pickle). - Debug modes enabled in production.
Trivy scans the final Docker image for OS-level vulnerabilities and outdated dependencies (CVEs).
- Layer 7 Protection: Ensures the base image (Python Slim) doesn't have known exploits.
- Gatekeeper: Even if the code is safe, a vulnerable OS package could compromise the pod. The pipeline fails on
CRITICALorHIGHseverity issues.
The pipeline is defined in .github/workflows/ci.yml.
- Action: Installs and runs
banditon theapp/directory. - Goal: Fail fast if security flaws are detected.
- Action: Builds the Docker image and pushes it to Docker Hub.
- Tagging: Uses the unique Git SHA (
${{ github.sha }}) to ensure immutability and traceability.
- Action: Pulled the pushed image and scans for CVEs.
- Policy: Fails the build if
CRITICALvulnerabilities are found.
- Action: Updates
k8s/deployment.yamlwith the new image tag. - Meaning: The repository itself is the "Single Source of Truth". Changing the manifest in the repo triggers the deployment process (Conceptually via ArgoCD or simple application).
- Docker Desktop (with Kubernetes enabled) or Minikube.
- Terraform installed.
- Python 3.9+ (for local testing).
-
Clone the repo:
git clone <repo-url> cd devops-finalproject/app
-
Run the App:
pip install fastapi uvicorn uvicorn main:app --reload
Access at
http://localhost:8000.
Initialize the Kubernetes namespace using Terraform.
cd terraform
terraform init
terraform apply
# Confirm 'yes' to create the 'final-project' namespaceApply the manifests to the cluster.
kubectl apply -f k8s/Add the local DNS entry (if using Minikube):
echo "$(minikube ip) devops-project.local" | sudo tee -a /etc/hostsThen visit http://devops-project.local.
- Monitoring: Add Prometheus & Grafana for metrics.
- Testing: Add
pytestfor unit testing before the security scan. - Secret Management: Replace K8s secrets with Vault.