Skip to content

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

4 Commits

Folders and files

Repository files navigation

⚑ hey-cicd β€” DevSecOps Dashboard

πŸ“ Project Structure

hey-cicd/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ app.py              # Flask application
β”‚   β”œβ”€β”€ templates/
β”‚   β”‚   └── index.html      # Dashboard UI
β”‚   └── static/
β”‚       β”œβ”€β”€ css/styles.css
β”‚       └── js/main.js
β”œβ”€β”€ tests/
β”‚   └── test_app.py         # Unit tests
β”œβ”€β”€ k8s/
β”‚   β”œβ”€β”€ deployment.yaml     # Kubernetes Deployment
β”‚   └── service.yaml        # Kubernetes Service
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── devsecops.yml   # CI/CD Pipeline
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ requirements-dev.txt
└── README.md

🌐 API Endpoints

Method Route Description
GET / Dashboard UI
GET /health Health check
GET /api/status App info, uptime, Python version
GET /api/greet/<name> Returns a greeting for the name
POST /api/add Adds two numbers
POST /api/calculate Calculator (add/subtract/multiply/divide/power/modulo)
POST /api/pipeline/run Simulates a CI/CD pipeline run

πŸ–₯️ Method 1 β€” Run Manually (Python)

Step 1 β€” Clone the repository

git clone https://github.com/YOUR_USERNAME/hey-cicd.git
cd hey-cicd

Step 2 β€” Create a virtual environment

python3 -m venv .venv
source .venv/bin/activate        # Mac/Linux
# .venv\Scripts\activate         # Windows

Step 3 β€” Install dependencies

pip install -r requirements.txt

Step 4 β€” Run the app

python3 app/app.py

Step 5 β€” Open in browser

http://localhost:5001

Step 6 β€” Run the tests

pip install -r requirements-dev.txt
python3 -m pytest --cov=app --cov-report=term-missing

Expected output:

tests/test_app.py::test_home                      PASSED
tests/test_app.py::test_health                    PASSED
tests/test_app.py::test_greet                     PASSED
tests/test_app.py::test_add_numbers               PASSED
tests/test_app.py::test_add_numbers_missing_fields PASSED
tests/test_app.py::test_calculator_multiply       PASSED
tests/test_app.py::test_calculator_divide_by_zero PASSED
tests/test_app.py::test_status                    PASSED
8 passed in 0.Xs

Test the API manually

# Health check
curl http://localhost:5001/health

# Greet someone
curl http://localhost:5001/api/greet/Nensi

# Add two numbers
curl -X POST http://localhost:5001/api/add \
  -H "Content-Type: application/json" \
  -d '{"number1": 10, "number2": 20}'

# Calculator
curl -X POST http://localhost:5001/api/calculate \
  -H "Content-Type: application/json" \
  -d '{"a": 6, "b": 3, "operation": "multiply"}'

🐳 Method 2 β€” Run with Docker

Prerequisites

Step 1 β€” Build the Docker image

docker build -t hey-cicd:latest .

Step 2 β€” Run the container

docker run -p 5001:5001 hey-cicd:latest

Step 3 β€” Open in browser

http://localhost:5001

Useful Docker commands

# See running containers
docker ps

# Stop the container
docker stop <container-id>

# Remove the image
docker rmi hey-cicd:latest

# Run in background (detached mode)
docker run -d -p 5001:5001 hey-cicd:latest

βš™οΈ Method 3 β€” CI/CD Pipeline (GitHub Actions)

The pipeline runs automatically every time you push code to main or open a pull request.

Pipeline Stages

Push to GitHub
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  STEP 1: Tests  β”‚  pytest β€” runs all 8 unit tests
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  STEP 2: SAST   β”‚  CodeQL β€” scans code for security issues
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   STEP 3: SCA   β”‚  pip-audit β€” checks for vulnerable packages
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ (all 3 must pass)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  STEP 4: Build  β”‚  docker build β€” creates the Docker image
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  STEP 5: Scan   β”‚  Trivy β€” scans the Docker image for CVEs
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  STEP 6: Push   β”‚  Pushes image to GitHub Container Registry
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ (only on push to main)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ STEP 7: Deploy  β”‚  kubectl apply β†’ deploys to Kubernetes
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

How to trigger the pipeline

# Make a change, commit, and push
git add .
git commit -m "your message"
git push origin main

Then go to your GitHub repo β†’ Actions tab to watch it run.

Required GitHub Secrets

Go to GitHub repo β†’ Settings β†’ Secrets and variables β†’ Actions and add:

Secret Name Value
KUBECONFIG Contents of your ~/.kube/config file (needed for Step 7 deploy)

ℹ️ GITHUB_TOKEN is automatically provided by GitHub β€” you don't need to add it manually.

View your Docker image after push

After Step 6 runs, your image is available at:

ghcr.io/YOUR_USERNAME/hey-cicd:latest

Go to GitHub repo β†’ Packages to see it.


☸️ Method 4 β€” Deploy to Kubernetes manually

Do this if you want to deploy without the pipeline, directly from your terminal.

Prerequisites

  • A running Kubernetes cluster (minikube, k3s, or cloud)
  • kubectl installed and connected to your cluster

Step 1 β€” Apply the manifests

kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml

Step 2 β€” Check the pods are running

kubectl get pods
kubectl get service session17-python

Step 3 β€” Access the app

# If using minikube
minikube service session17-python

# Or access via NodePort
http://<your-node-ip>:30001

Useful kubectl commands

# See all running pods
kubectl get pods

# See logs from a pod
kubectl logs <pod-name>

# Delete the deployment
kubectl delete -f k8s/deployment.yaml
kubectl delete -f k8s/service.yaml

πŸ§ͺ DevSecOps Concepts Covered

Concept Tool Used Where
Unit Testing pytest + pytest-cov tests/test_app.py
SAST (Static Application Security Testing) GitHub CodeQL Pipeline Step 2
SCA (Software Composition Analysis) pip-audit Pipeline Step 3
Containerisation Docker Dockerfile
Container Image Scanning Trivy Pipeline Step 5
Container Registry GitHub Container Registry (GHCR) Pipeline Step 6
Orchestration Kubernetes k8s/ folder
CI/CD Automation GitHub Actions .github/workflows/devsecops.yml

πŸ‘©β€πŸ’» Built With

  • Python 3.12 + Flask 3.x
  • Docker
  • Kubernetes
  • GitHub Actions

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages