This repository demonstrates a complete CI/CD pipeline for implementing Blue-Green Deployment using Jenkins, Kubernetes, Docker, SonarQube, Nexus, Trivy, Ansible and Terraform. It is designed for deploying and managing a Next.js portfolio application with automated testing, scanning, and artifact management.
.
├── Dockerfile # Docker image definition
├── Jenkinsfile # Jenkins pipeline definition
├── README.md # Project documentation
├── ansible # Configuration management with Ansible
│ ├── ansible.cfg
│ ├── inventory.ini # Hosts and credentials of VMs
│ ├── playbook.yml
│ └── roles
│ ├── docker # Role for Docker setup
│ ├── jenkins # Role for Jenkins setup
│ ├── kubectl # Role for Kubernetes setup
│ ├── nexus # Role for Nexus setup
│ ├── npm # Role for npm setup
│ ├── sonarqube # Role for SonarQube setup
│ └── trivy # Role for Trivy setup
├── app # Next.js application source code
├── init.sh # Initiliase and Configuring the VMs
├── app-deployment-blue.yml # Blue environment Kubernetes deployment
├── app-deployment-green.yml # Green environment Kubernetes deployment
├── portfolio-service.yml # LoadBalancer to switch between deployments
├── cluster_config # Kubernetes cluster configuration
│ ├── role.yml
│ ├── rolebinding.yml
│ ├── sec.yml
│ └── service_account.yml
├── components # Modular React components
├── terraform # Terraform configuration for infrastructure provisioning
│ ├── main.tf
│ ├── output.tf
│ └── variables.tf
└── public # Static assets for the application
-
CI/CD Pipeline
- Automated build, test, and deployment using Jenkins.
- Quality gate check with SonarQube.
- Dependency scanning with Trivy.
-
Blue-Green Deployment
- Zero-downtime deployments.
- Traffic switching between Blue and Green environments.
-
Infrastructure as Code (IaC)
- Infrastructure provisioning using Terraform.
-
Configuration Management
- Infrastructure setup and configuration using Ansible.
- Automated installation and configuration of tools.
- Idempotent and repeatable deployments.
- Role-based configuration management.
-
Artifact Management
- Artifacts published and stored in Nexus.
-
Security Scanning
- File system and container image scanning using Trivy.
The Jenkins pipeline (defined in Jenkinsfile) consists of the following stages:
- Git Checkout: Fetch the source code from the GitHub repository.
- Trivy FS Scan: Perform file system vulnerability scanning.
- SonarQube Analysis: Analyze code quality and maintainability.
- Quality Gate Check: Ensure the code meets predefined quality standards.
- Install Dependencies: Install npm dependencies.
- Build Next.js App: Build the application for production.
- Setup .npmrc: Configure npm with credentials.
- Publish Artifacts: Publish build artifacts to Nexus.
- Docker Build & Push: Build and push the Docker image to the registry.
- Trivy Image Scan: Scan Docker images for vulnerabilities.
- Deploy SVC-APP: Deploy the application to Kubernetes.
- Blue Environment: Defined in
app-deployment-blue.yml. - Green Environment: Defined in
app-deployment-green.yml. - Traffic can be switched between environments using the
SWITCH_TRAFFICparameter in the Jenkins pipeline.
Kubernetes configurations are stored in the cluster_config directory, including roles, role bindings, service accounts, and security settings.
- Jenkins with necessary plugins:
- Pipeline
- Blue Ocean
- Kubernetes
- SonarQube Scanner
- Docker installed and running.
- Kubernetes Cluster for deploying the application.
- Terraform for provisioning infrastructure.
- Nexus for artifact management.
- SonarQube for code quality checks.
- Trivy for vulnerability scanning.
- Ansible for configuration management.
-
Clone the repository:
git clone https://github.com/PPT1001/Blue-Green-Deployment-Project.git cd Blue-Green-Deployment-Project -
Configure Jenkins:
- Import the
Jenkinsfileinto a new Jenkins pipeline. - Set up credentials for GitHub, Docker, Nexus, and SonarQube.
- Import the
-
Set up Kubernetes:
- Apply the configurations in
cluster_config.
- Apply the configurations in
-
Deploy the Application:
- Run the Jenkins pipeline with the desired
DEPLOY_ENVandDOCKER_TAG.
- Run the Jenkins pipeline with the desired
- Jenkins: CI/CD automation.
- Docker: Containerization.
- Kubernetes: Container orchestration.
- SonarQube: Code quality analysis.
- Trivy: Security scanning.
- Nexus: Artifact repository.
- Terraform: Infrastructure as Code (IaC).
- Ansible: Configuration management.
- Next.js: Frontend framework.