This project demonstrates a complete CI/CD pipeline using GitHub Actions, Docker, and Minikube. It automates building, testing, scanning, and deploying a containerized application.
- Repository: github.com/mrckurz/cicd-workshop
- Technologies: GitHub Actions, Docker, Trivy, SonarCloud, Minikube
- Pipeline Stages:
- Build Docker image
- Push image to Docker Hub
- Run vulnerability scan with Trivy
- Perform code quality analysis with SonarCloud
- Deploy to local Minikube cluster
This repository follows a structured branching model to progressively build the CI/CD pipeline step by step. Each branch represents a different step in the pipeline implementation.
- Description: This is the primary branch where the complete solution resides. All final code and configurations for the CI/CD pipeline, Docker setup, security scanning, and deployment are merged into this branch.
- Usage: The
mainbranch contains the finished version of the pipeline that runs on GitHub Actions, including all the stages like build, push, vulnerability scan, code analysis, and deployment to Minikube.
These branches represent intermediate steps of the CI/CD pipeline implementation and allow for incremental learning.
- Description: This branch sets up the initial pipeline structure with a simple
echocommand to verify pipeline execution. - Focus: Introducing the
.github/workflows/go.ymlfile and understanding basic pipeline operations. - Use Case: When starting with CI/CD basics and setting up the first workflow.
- Description: This branch adds a job to build a Docker image for the project.
- Focus: Adding Docker build commands and understanding how to package applications into containers.
- Use Case: Building the Docker image and pushing it to Docker Hub.
- Description: This branch adds the Trivy vulnerability scan to ensure security checks for the Docker image.
- Focus: Integrating Trivy into the pipeline to scan for known vulnerabilities in the image.
- Use Case: Enhancing security by scanning images for vulnerabilities before deployment.
- Description: This branch adds the SonarCloud integration for code quality analysis.
- Focus: Configuring SonarCloud to analyze the source code for quality issues and maintainability.
- Use Case: Adding code quality checks to the pipeline to ensure the health of the codebase.
- Description: This branch adds the deployment step to Minikube, enabling automatic deployment of the built image to a local Kubernetes cluster.
- Focus: Deploying Docker containers to a Kubernetes cluster using Minikube.
- Use Case: Testing and deploying the application in a Kubernetes environment locally.
Each step allows incremental learning and builds on top of the previous one. These branches give a clear progression for setting up a complete CI/CD pipeline.
- Git: Download
- Docker Desktop: Download
- Minikube: Installation Guide
- kubectl: Installation Guide
- GitHub-hosted Runner (automatic): Installation Guide
- Homebrew: Installation Guide
- Git:
brew install git - Docker Desktop: Download
- Minikube:
brew install minikube - kubectl:
brew install kubectl - GitHub-hosted Runner (automatic): Installation Guide
- Git:
sudo apt install gitorsudo yum install git - Docker: Installation Guide
- Minikube: Installation Guide
- kubectl: Installation Guide
- GitHub-hosted Runner (automatic): Installation Guide
The .github/workflows/go.yml defines the following stages:
- Image:
docker:latest - Script:
- Build Docker image tagged with
latestand commit SHA.
- Build Docker image tagged with
- Image:
docker:latest - Script:
- Push both
latestand commit SHA tags to Docker Hub.
- Push both
- Image:
aquasec/trivy:latest - Script:
- Scan the Docker image for vulnerabilities using Trivy.
- Image:
sonarsource/sonar-scanner-cli:latest - Script:
- Run SonarCloud analysis using
sonar-scanner. - Requires
SONAR_TOKENenvironment variable.
- Run SonarCloud analysis using
- Image:
docker:latest - Script:
- Deploy the Docker image to Minikube using
redeploy.sh.
- Deploy the Docker image to Minikube using
docker build -t mrckurz/cicd-workshop-image:latest -t mrckurz/cicd-workshop-image:$(git rev-parse --short HEAD) .docker push mrckurz/cicd-workshop-image:latest
docker push mrckurz/cicd-workshop-image:$(git rev-parse --short HEAD)trivy image mrckurz/cicd-workshop-image:latestsonar-scanner -Dsonar.projectKey=your_project_key -Dsonar.organization=your_org -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN./redeploy.shminikube startkubectl apply -f minikube-deployment.yaml./redeploy.shminikube service cicd-workshopcicd-workshop/
βββ .github/workflows/ci.yml
βββ Dockerfile
βββ README.md
βββ redeploy.sh
βββ minikube-deployment.yaml
βββ go.mod
βββ go.sum
βββ main.go