Skip to content

mrCrpn/cicd_workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

52 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CI/CD Workshop: GitHub + Docker + Minikube

This project demonstrates a complete CI/CD pipeline using GitHub Actions, Docker, and Minikube. It automates building, testing, scanning, and deploying a containerized application.

πŸš€ Project Overview

  • 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

🌿 Branches

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.

Main Branch (main)

  • 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 main branch 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.

Step-by-Step Branches

These branches represent intermediate steps of the CI/CD pipeline implementation and allow for incremental learning.

Step 1: step-1-base-setup

  • Description: This branch sets up the initial pipeline structure with a simple echo command to verify pipeline execution.
  • Focus: Introducing the .github/workflows/go.yml file and understanding basic pipeline operations.
  • Use Case: When starting with CI/CD basics and setting up the first workflow.

Step 2: step-2-docker-build

  • 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.

Step 3: step-3-vulnerability-scan

  • 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.

Step 4: step-4-sonarcloud

  • 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.

Step 5: step-5-deploy-minikube

  • 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.


🧰 Prerequisites

Windows

macOS

Linux


πŸ§ͺ CI/CD Pipeline Explained

The .github/workflows/go.yml defines the following stages:

1. Build

  • Image: docker:latest
  • Script:
    • Build Docker image tagged with latest and commit SHA.

2. Push

  • Image: docker:latest
  • Script:
    • Push both latest and commit SHA tags to Docker Hub.

3. Vulnerability Scan

  • Image: aquasec/trivy:latest
  • Script:
    • Scan the Docker image for vulnerabilities using Trivy.

4. Code Quality Analysis

  • Image: sonarsource/sonar-scanner-cli:latest
  • Script:
    • Run SonarCloud analysis using sonar-scanner.
    • Requires SONAR_TOKEN environment variable.

5. Deploy

  • Image: docker:latest
  • Script:
    • Deploy the Docker image to Minikube using redeploy.sh.

πŸ›  Manual Commands

Build Docker Image

docker build -t mrckurz/cicd-workshop-image:latest -t mrckurz/cicd-workshop-image:$(git rev-parse --short HEAD) .

Push Docker Image

docker push mrckurz/cicd-workshop-image:latest
docker push mrckurz/cicd-workshop-image:$(git rev-parse --short HEAD)

Run Trivy Scan

trivy image mrckurz/cicd-workshop-image:latest

Run SonarCloud Analysis

sonar-scanner -Dsonar.projectKey=your_project_key -Dsonar.organization=your_org -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN

Deploy to Minikube

./redeploy.sh

🧭 Minikube Deployment Guide

1. Start Minikube

minikube start

2. Apply Deployment Configuration

kubectl apply -f minikube-deployment.yaml

3. Deploy Application

./redeploy.sh

4. Access the Application

minikube service cicd-workshop

πŸ“‚ Project Structure

cicd-workshop/
β”œβ”€β”€ .github/workflows/ci.yml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ README.md
β”œβ”€β”€ redeploy.sh
β”œβ”€β”€ minikube-deployment.yaml
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
└── main.go

🏷️ GitHub Badges

Build Docker Pulls

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages