================================= DevOps Project Setup ( CI & CD ) ================================= In this project we are using below devops tools 1) Git Hub 2) Maven 3) SonarQube 4) Nexus 5) Trivy 6) Docker 7) Kubernetes 8) Jenkins =================== DB Setup =================== Step-1 :: Setup AWS RDS MySQL Instance and note down DB details DB Endpoint : mysql-dev-db.cjmqwwo0a08x.ap-south-1.rds.amazonaws.com DB Username : admin DB Password : AshokIT321 Step-2 :: Connect with MySQL DB using Workbench s/w and execute sql queries to insert products data into db tables. Note: DB Queries file available in backend_app git repo # Backend App Git Repo : https://github.com/ashokitschool/01_products_api.git DB Queries File Name: DB_Setup.sql ########################### CI JOB Setup ############################ ============== Jenkins Setup ============== @@@ Step-1 :: Setup Jenkins Server : https://github.com/ashokitschool/DevOps-Documents/blob/main/01-Jenkins-Server-Setup.md uname : ashokit pwd : ashokit @@@ Step-2 :: Configure Maven as Global Tool in Jenkins Manage Jenkins -> Tools -> Maven Installation -> Add maven Maven Tool name : Maven-3.9.10 @@@ Step-3 :: Configure RDS DB instance connectivity Details in backend app git repo # Backend App Git Repo : https://github.com/ashokitschool/01_products_api.git File to change : src/main/resources/application.properties @@@ Step-4 :: Create CI JOB to build backend application Stage-1 : Clone Git Repo Stage-2 : Maven Build ``` pipeline { agent any tools{ maven "Maven-3.9.10" } stages { stage('Git clone') { steps { git branch: 'main', url: 'https://github.com/ashokitschool/01_products_api.git' } } stage('Mvn Build') { steps { sh 'mvn clean package' } } } } ``` ======================= SonarQube Integration ======================= @@@ Step-1 :: Setup SonarQube Server @@ Steps : https://github.com/ashokitschool/DevOps-Documents/blob/main/06-Sonar-Setup-Docker.md @@ Generate Sonar Token : sqa_ae95877407c19c7b633dd5c66a579efc3fe2c943 @@@ Step-2 :: Add Sonar Token in 'Jenkins Credentials' as Secret Text -> Manage Jenkins -> Credentials -> Add Credentials -> Select Secret text -> Enter Sonar Token as secret text @@@ Step-3 :: Install SonarQube Scanner Plugin -> Manage Jenkins -> Plugins -> Available -> Sonar Qube Scanner Plugin -> Install it @@@ Step-4 :: Configure SonarQube Server -> Manage Jenkins -> Configure System -> Sonar Qube Servers -> Add Sonar Qube Server - Name : Sonar-Server-AIT - Server URL : http://52.66.247.11:9000/ - Select Sonar Server Token @@@ Step-5 :: Add SonarQube Stage in Jenkins Pipeline ``` stage('Code Review') { steps { withSonarQubeEnv('Sonar-Server-AIT'){ sh 'mvn sonar:sonar' } } } ``` ================== Nexus Integration ================== @@@ Step-1 :: Setup Nexus Server Steps : https://github.com/ashokitschool/DevOps-Documents/blob/main/07-Nexus-Setup-Docker.md Username : admin Pwd : AshokIT321 @@@ Step-2 :: Create Repository in Nexus Repo Type : Maven2 (Hosted) repo name : ashokit-artifact-repo Repo Url : http://43.205.213.177:8081/repository/ashokit-artifact-repo/ @@@ Step-3 :: Install Nexus Repository Plugin -> Manage Plugins -> Available Pluging -> Plugin Name : Nexus Artifact Uploader @@@ Step-4 :: Configure Nexus Upload stage in Jenkins Pipeline (use pipeline syntax to generate script) ``` stage('Nexus Upload') { steps { nexusArtifactUploader artifacts: [ [ artifactId: '01_products_api', classifier: '', file: 'target/products_api.jar', type: 'jar' ] ], credentialsId: 'NEXUS-CREDENTIALS', groupId: 'in.ashokit', nexusUrl: '43.205.213.177:8081', nexusVersion: 'nexus3', protocol: 'http', repository: 'ashokit-artifact-repo', version: '1.0' } } ``` ==================== Docker Integration ==================== @@@ Step-1 :: Setup Docker s/w in Jenkins Server ``` sudo apt update curl -fsSL get.docker.com | /bin/bash sudo usermod -aG docker ubuntu sudo usermod -aG docker jenkins sudo systemctl restart docker sudo systemctl restart jenkins exit ``` @@@ Step-2 :: Add Stage to create Docker Image ``` stage('Docker Image') { steps { sh 'docker build -t ashokit/ecomm_backend_api .' } } ``` @@@ Step-3 :: Add Stage to Push Docker Image to docker Hub stage('Push Docker Image') { steps { sh 'docker login -u ashokit -p token' sh 'docker push ashokit/ecomm_backend_api' } } ==================== Trivy Integration ==================== @@@ Step-1 :: Setup Trivy Jenkins Server ``` sudo apt update -y curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sudo sh -s -- -b /usr/local/bin ``` @@@ Step-2 :: Add Trivy Scanning stage in Jenkins Pipeline ``` stage('Trivy Scan') { steps { script { sh ''' docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \ aquasec/trivy image --severity CRITICAL,HIGH ashokit/ecomm_backend_api ''' } } } ``` ########################### CD JOB Setup ############################ @@@ Step-1 : Setup EKS Cluster ### Setup Doc : https://github.com/ashokitschool/DevOps-Documents/blob/main/05-EKS-Setup.md Step-2 : Jenkins with Kubernetes (EKS) Integration - Attach EKS IAM Role to Jenkins Server - Install AWS CLI in Jenkins Server - Install Kubectl in Jenkins Server - Update EKS Cluster Config File in Jenkins Server ### Setup Doc : https://github.com/ashokitschool/DevOps-Documents/blob/main/10-Jenkins-Docker-K8S.md @@@ Step-3 : Create CD JOB ``` pipeline { agent any stages { stage('Git clone') { steps { git branch: 'main', url: 'https://github.com/ashokitschool/01_products_api.git' } } stage('k8s deployment') { steps { sh 'kubectl apply -f k8s-deploy.yml' } } } } ``` @@@ Step-4 : Trigger CD JOB From CI JOB (add new stage in CI JOB) @@@ Step-5 : Run CI JOB (it will trigger CD also)