Project on End to End CI/CD pipeline for java based application using Git,Github,Jenkins,Maven,Sonarqube,Nexus,Slack,Docker and Kuberenets with ECR as private docker registry and Zero Downtime Deployment

Overview

Description

Project on End to End CI/CD pipeline for java based application using Git,Github,Jenkins,Maven,Sonarqube,Nexus,Slack,Docker and Kuberenets with ECR as private docker registry and Zero Downtime Deployment.

end-to-end-cicd-FLOW


Project Flow

1. Developer pushes code into Github.
2. Webhook triggers Jenkins when there is a change in the code
3. Jenkins Pulls the Code from the Github
4. Maven builds the code and generates artifacts
5. Code quality is measured with Sonarqube
6. Quality Gate Check , If Quality Gate Fails Jenkins Job will fail !!!!!! (Triggered by Sonarqube Webhooks)
7. Upload artifact generated into Sonatype Nexus . It will dynamically choose Snapshot or release repository based on the version tag in pom.xml
8. Build Docker Image based on the Dockerfile with projectname && commit-id as tag . So each time it will be different.
9. Push Docker Image to private ECR docker registry.
10.Dynamically change image in pod template in manifest file.
11.Deploy to K8s cluster created with kubeadm . It will pull image from private registry.
12. Send Build Notification over Slack Channel and email notification when build is success/failure.

Note: We can add an approval step before deploying to K8s cluster as an input from user.

Features

1. Zero downtime deployment with rolling update as deployment strategy
2. Complete automation as when developer check in code , deployed to k8s cluster
3. Versioning of docker images , build artifacts.
4. Code checked against Code coverage and whether coding stantards are met.

Pipeline Execution

JENKINS-PIPELINE-VIEW-MAIN

Execution Results

SONARQUBE REPORTS

SONAR REPORT

NEXUS UPLOADING

NEXUS REPOSITORY

ECR

ECR REPO

JOB TRIGGERED BY WEBHOOKS

GITHUB-WEBHOOK-PUSH

K8s CLUSTER

Controller --> Deployment
Strategy --> Rolling Update

K8S cluster

SLACK NOTIFICATION

SLACK - NOTIFICATION

EMAIL NOTIFICATION

EMAIL NOTIFICATION

FINAL RESULT

FINAL UPDATE

Jenkins Pipeline

)" emailext attachLog: true, body: '''BUILD IS SUCCESSFULL - $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS: Check console output at $BUILD_URL to view the results. Regards, Nithin John George ''', compressLog: true, replyTo: '[email protected]', subject: '$PROJECT_NAME - $BUILD_NUMBER - $BUILD_STATUS', to: '[email protected]' } failure { slackSend channel: 'build-notifications',color: 'danger', message: "started JOB : ${env.JOB_NAME} with BUILD NUMBER : ${env.BUILD_NUMBER} BUILD_STATUS: - ${currentBuild.currentResult} To view the dashboard (<${env.BUILD_URL}|Open>)" emailext attachLog: true, body: '''BUILD IS FAILED - $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS: Check console output at $BUILD_URL to view the results. Regards, Nithin John George ''', compressLog: true, replyTo: '[email protected]', subject: '$PROJECT_NAME - $BUILD_NUMBER - $BUILD_STATUS', to: '[email protected]' } } } ">
def COMMIT
def BRANCH_NAME
def GIT_BRANCH
pipeline
{
 agent any
 environment
 {
     AWS_ACCOUNT_ID="930264708953"
     AWS_DEFAULT_REGION="us-east-1" 
     IMAGE_REPO_NAME="mavenwebapp"
     REPOSITORY_URI = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}"
     
 }
 tools
 {
      maven 'MAVEN_3.8.4'
 }   

 options 
 {
  buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '4', daysToKeepStr: '', numToKeepStr: '4')
  timestamps()
}
 stages
 {
     stage('Code checkout')
     {
         steps
         {
             script
             {
                 checkout([$class: 'GitSCM', branches: [[name: '*/development']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/dev1git/maven-web-application.git']]])
                 COMMIT = sh (script: "git rev-parse --short=10 HEAD", returnStdout: true).trim()  
                 BRANCH_NAME = sh(script: 'git name-rev --name-only HEAD', returnStdout: true)
                 GIT_BRANCH = BRANCH_NAME.substring(BRANCH_NAME.lastIndexOf('/') + 1, BRANCH_NAME.length()) 
                 
                 

             }
             
         }
     }
     stage('Build')
     {
         steps
         {
             sh "mvn clean package"
         }
     }
     stage('Execute Sonarqube Report')
     {
         steps
         {
            withSonarQubeEnv('Sonarqube-Server') 
             {
                sh "mvn sonar:sonar"
             }  
         }
     }
     stage('Quality Gate Check')
     {
         steps
         {
             timeout(time: 1, unit: 'HOURS') 
             {
                waitForQualityGate abortPipeline: true, credentialsId: 'SONARQUBE-CRED'
            }
         }
     }
     
     stage('Nexus Upload')
     {
         steps
         {
             script
             {
                 def readPom = readMavenPom file: 'pom.xml'
                 def nexusrepo = readPom.version.endsWith("SNAPSHOT") ? "wallmart-snapshot" : "wallmart-release"
                 nexusArtifactUploader artifacts: 
                 [
                     [
                         artifactId: "${readPom.artifactId}",
                         classifier: '', 
                         file: "target/${readPom.artifactId}-${readPom.version}.war", 
                         type: 'war'
                     ]
                ], 
                         credentialsId: 'Nexus-Cred', 
                         groupId: "${readPom.groupId}", 
                         nexusUrl: '3.82.213.203:8081', 
                         nexusVersion: 'nexus3', 
                         protocol: 'http', 
                         repository: "${nexusrepo}", 
                         version: "${readPom.version}"

             }
         }
     }
     stage('Login to AWS ECR')
     {
         steps
         {
             script
             {
                 sh "/usr/local/bin/aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
             }
         }
     }
     stage('Building Docker Image')
     {
         steps
         {
             script
             {
              sh "docker build . -t ${REPOSITORY_URI}:mavenwebapp-${COMMIT}"
             }
         }
     }
     stage('Pushing Docker image into ECR')
     {
         steps
         {
             script
             {
                 sh "docker push ${REPOSITORY_URI}:mavenwebapp-${COMMIT}"
             }
         }

     }
     stage('Update image in K8s manifest file')
     {
         steps
         {
             
                 sh """#!/bin/bash
                 sed -i 's/VERSION/$COMMIT/g' deployment.yaml
                 """
             }
         }
     
     stage('Deploy to K8s cluster')
     {
         steps
         {
             sh 'kubectl apply -f deployment.yaml --record=true'
             sh """#!/bin/bash
             sed -i 's/$COMMIT/VERSION/g' deployment.yaml
             """

         }
     }
 }

 post
 {
     always
     {
         cleanWs()
     }
     success
     {
        slackSend channel: 'build-notifications',color: 'good', message: "started  JOB : ${env.JOB_NAME}  with BUILD NUMBER : ${env.BUILD_NUMBER}  BUILD_STATUS: - ${currentBuild.currentResult} To view the dashboard (<${env.BUILD_URL}|Open>)"
        emailext attachLog: true, body: '''BUILD IS SUCCESSFULL - $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
 
        Check console output at $BUILD_URL to view the results.
 
        Regards,
 
        Nithin John George
        ''', compressLog: true, replyTo: '[email protected]', 
        subject: '$PROJECT_NAME - $BUILD_NUMBER - $BUILD_STATUS', to: '[email protected]'
     }
     failure
     {
         slackSend channel: 'build-notifications',color: 'danger', message: "started  JOB : ${env.JOB_NAME}  with BUILD NUMBER : ${env.BUILD_NUMBER}  BUILD_STATUS: - ${currentBuild.currentResult} To view the dashboard (<${env.BUILD_URL}|Open>)"
         emailext attachLog: true, body: '''BUILD IS FAILED - $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
 
        Check console output at $BUILD_URL to view the results.
 
        Regards,
 
        Nithin John George
        ''', compressLog: true, replyTo: '[email protected]', 
        subject: '$PROJECT_NAME - $BUILD_NUMBER - $BUILD_STATUS', to: '[email protected]'
     }
 }

}

K8s manifest File (Deployment)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mavenwebapp-dp
  labels:
    app: mavenwebapp
spec:
  replicas: 4
  revisionHistoryLimit: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 1
  minReadySeconds: 30
  selector:
    matchLabels:
       app: mavenwebapp
  template:
    metadata:
      name: mavenwebapp-pod
      labels:
        app: mavenwebapp
    spec:
      imagePullSecrets:
      - name: regcrd
      containers:
      - name: mavenwebapp-container
        image: 930264708953.dkr.ecr.us-east-1.amazonaws.com/mavenwebapp:mavenwebapp-VERSION
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        resources:
          requests:
            cpu: 300m
            memory: 256Mi
          limits:
            cpu: 800m
            memory: 1Gi
 
---

apiVersion: v1
kind: Service
metadata:
  name: mavenwebapp-svc
spec:
  type: NodePort
  selector:
    app: mavenwebapp
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 30003

Docker File

FROM tomcat:8.0.20-jre8
 
COPY target/java-web-app*.war /usr/local/tomcat/webapps/java-web-app.war
You might also like...

BlockChain Pipeline using Jenkins for DevOps

BlockChain Pipeline for Jenkins This project is inspired by the work of Redback and Microsoft teams for developing the process using VSTS. I've chosen

Jun 8, 2022

A Jenkins plugin for inserting the commits changelog into the jenkins build environment.

commits-changelog-env-plugin A Jenkins plugin for inserting the commits changelog into the jenkins build environment. Jenkins插件, 在构建时通过将提交的更新列表插入 Jenk

Feb 16, 2022

Jenkins plugin exposes functionalities for the Popcorn by Lectra open-source Jenkins platform on Kubernetes

Popcorn Jenkins Plugin This Jenkins plugin exposes functionalities for the Popcorn by Lectra open-source Jenkins platform on Kubernetes. This plugin i

Apr 6, 2022

An intelliJ plugin providing a UI layer for git-flow, which in itself is a collection of Git extensions to provide high-level repository operations for Vincent Driessen's branching model.

An intelliJ plugin providing a UI layer for git-flow, which in itself is a collection of Git extensions to provide high-level repository operations for Vincent Driessen's branching model.

Git Flow Integration Plus for Intellij An intelliJ plugin providing a UI layer for git-flow, which in itself is a collection of Git extensions to prov

Nov 8, 2022

Make Slack and Facebook Bots in Java.

Make Slack and Facebook Bots in Java.

JBot Make bots in Java. JBot is a java framework (inspired by Howdyai's Botkit) to make Slack and Facebook bots in minutes. It provides all the boiler

Dec 18, 2022

Spring-boot project using open-api, docker, maven, REST

library-service spring-boot project using open-api, docker, maven, REST I used docker to run the project, as well as open-api to generate basic GET an

Nov 27, 2022

End to End project for Kafka Streams using Spring Cloud Kafka streams

End to End project for Kafka Streams using Spring Cloud Kafka streams

Spring Kafka Streams using Spring Cloud Streams End to End example Endpoint http://localhost:8080/domain/lookup/facebook - to pull all facebook relate

Dec 20, 2022

hello-git-taqiyaehsan created by GitHub Classroom

👋 The Basics of GitHub 🤓 Course overview and learning outcomes The goal of this course is to give you a brief introduction to GitHub. We’ll also pro

Feb 3, 2022

GithubReleases4J - GitHub Releases for Java , based on GitHub RESTful API .

GithubReleases4J - GitHub Releases for Java , based on GitHub RESTful API .

Jun 27, 2022

GitHub Search Engine: Web Application used to retrieve, store and present projects from GitHub, as well as any statistics related to them.

GHSearch Platform This project is made of two subprojects: application: The main application has two main responsibilities: Crawling GitHub and retrie

Nov 25, 2022

Deploying Spring Boot and MongoDB as Containers Using Docker and Docker Compose

springboot-mongodb-docker Deploying Spring Boot and MongoDB as Containers Using Docker and Docker Compose Steps & Commands pull mongo image from docke

Nov 25, 2022

AWS Service registry for resilient mid-tier load balancing and failover.

Eureka Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose

Dec 30, 2022

Sonatype Nexus Repository Open Source Codebase

Builds use Apache Maven and require Java 8. Apache Maven wrapper scripts are included in the source tree.

Jan 5, 2023

Demo for schema references feature on the Confluent Schema Registry

Schema references demos This project aims to showcase the schema references feature on Confluent Schema Registry. Two distinct use case are considered

Sep 5, 2022

A Nexus Repository 3 plugin that allows usage of Terraform repositories

Nexus Repository Terraform Format Table Of Contents Developing Requirements Download Building Using Terraform with Nexus Repository Manager 3 Compatib

Dec 5, 2022

The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker.

gke-springboot-sampleapp 👋 The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker. Usage To be

Feb 1, 2022
Owner
NITHIN JOHN GEORGE
NITHIN JOHN GEORGE
Helium is an open source event dispatcher using ReflectASM

Helium is an open source event dispatcher using ReflectASM Helium is not finished, and once it is ready i will make it so you can add it as a d

max! 17 Apr 30, 2021
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13

JavaParser This project contains a set of libraries implementing a Java 1.0 - Java 14 Parser with advanced analysis functionalities. This includes pre

JavaParser 4.5k Jan 5, 2023
Java library for handling exceptions in concise, unified, and architecturally clean way.

NoException NoException is a Java library for handling exceptions in concise, unified, and architecturally clean way. System.out.println(Exceptions.lo

Robert Važan 79 Nov 17, 2022
simple tail call optimization and stack safety for Java

com.github.kag0.tail simple tail call optimization for Java enables infinitely deep tail recursive calls without throwing a StackOverflowError no tran

Nathaniel Fischer 18 Dec 7, 2022
Dynamic Code Evolution VM for Java 7/8

NEWS: Dcevm-11 on Trava OpenJDK There is a new distribution channel for DCEVM-11 binaries on - TravaOpenjdk! DCEVM This project is a fork of original

null 1.6k Dec 28, 2022
A library that simplifies error handling for Functional Programming in Java

Faux Pas: Error handling in Functional Programming Faux pas noun, /fəʊ pɑː/: blunder; misstep, false step Faux Pas is a library that simplifies error

Zalando SE 114 Dec 5, 2022
Java unlimited redefinition of classes at runtime.

Hotswap Agent This is an overview page, please visit hotswapagent.org for more information. Overview Java unlimited runtime class and resource redefin

null 1.9k Dec 30, 2022
SneakyThrow is a Java library to ignore checked exceptions

SneakyThrow SneakyThrow is a Java library to ignore checked exceptions. You can integrate it using maven: <dependency> <groupId>com.rainerhahnekamp<

Rainer Hahnekamp 73 Nov 8, 2022
An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or to turn an existing project into a devops project using open source software (Git, Docker, Jenkins..)

DevOpsify Description An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or t

obaydah bouifadene 14 Nov 8, 2022