DevOps β CI-CD Project
π‘ Building a CI/CD Pipeline Project with Git, Docker, SonarQube, Jenkins, and Nexus.
In this Project, we need to create 3 instances
Instance Name = Project -1 β Git, Docker, Maven, Jenkins
Instance Name = Project -2 β SonarQube
Instance Name = Project -3 β Docker, Nexus
STEP 1: Create t2.medium instance on Ubuntu 20.04 LTS (project-1)
STEP 2: Connect with the terminal and login as an Ubuntu user and switch to root user using the sudo su command
STEP 3: Packages to Install β Git, Docker, Maven, Java-11, Jenkins
apt update
apt install git docker.io βy
systemctl start Docker
cd /opt
wget <http://mirrors.estointernet.in/apache/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz>
tar -xvxf apache-maven-3.8.5-bin.tar.gz
apt search openjdk
apt install openjdk-11-jdk-headless
#To install jenkins
curl -fsSL <https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key> | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] <https://pkg.jenkins.io/debian-stable> binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
jenkins βversion
STEP 4: Hit instance IP along with port number 8080 in web
cat /var/lib/jenkins/secrets/initialAdminPassword
Jenkins Dashboard
Dashboard β Manage Jenkins β Plugin Manager (Install without restart)
Dashboard β Manage Jenkins β Global tool configuration β Add maven name & path
Dashboard β Manage Jenkins β Credentials β System β Global credentials
Step 5: Create Instance in t2.medium (2 CPU, 4Gib Memory) for SonarQube installation (Project -2)
STEP 6: Install Java which is pre-requisite for SonarQube
apt update
apt search openjdk
apt install openjdk-11-jdk-headless
java βversion
STEP 7: Create Subnet groups with all availability zones
STEP 8: Create RDS
Select Free Tier
Change DB Name
Create username and password
Security groups β all tcp
apt update
apt install mysql-server
mysql -h sonar-db.cfmucs0uutge.ap-south-1.rds.amazonaws.com -P 3306 -u admin βp
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER sonar@localhost IDENTIFIED BY 'sonar';
CREATE USER sonar@'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO sonar@localhost;
GRANT ALL ON sonar.* TO sonar@'%';
quit
STEP 9: Sonar Installation
cd /opt
wget <https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.6.zip>
apt install unzip
unzip sonarqube-6.7.6.zip
STEP 10: Edit sonar config files
cd /opt/sonarqube-6.7.6/conf
vi sonar.properties
(add username and password, add rds endpoint instead of localhost)
(Uncomment the highlighted lines)
sudo update-alternatives --config java
vi wrapper.conf
paste the java path
(we need to change the files permission from root to ubuntu in the path /bin/linux-x86β64)
chown -R ubuntu:ubuntu /opt/sonarqube-6.7.6
(Exit to the Ubuntu user and change directory to bin path and start the ./sonar.sh)
(login as βu admin βp admin)
(generate and copy the token)
STEP 11: Install plugins for sonar
(Add credential for sonar and paste token on secret)
(Configure system β add name, url and token)
STEP 12: Create a new instance for Nexus (Project -3)
apt update
apt search openjdk
apt install openjdk-8-jdk
apt install docker.io
STEP 13: Install NEXUS
(webpage url: https://help.sonatype.com/repomanager3/product-information/download)
cd /opt
wget <https://download.sonatype.com/nexus/3/nexus-3.53.0-01-unix.tar.gz>
tar -xvf nexus-3.53.0-01-unix.tar.gz
Password get from the path [ cd /opt/sonatype-work/nexus3/admin.password ]
STEP 14: Select project-1 instance (where Jenkins and docker installed )
vi /etc/docker/daemon.json
{
"insecure-registries" : ["nexus_instance_IP:docker_repo_port"]
}
service docker restart
node{
stage('SCM Checkout'){
git '<https://github.com/rajcloud12/my-app.git>'
}
stage('maven-buildstage'){
def mvnHome = tool name: 'maven3', type: 'maven'
sh "${mvnHome}/bin/mvn package"
sh 'mv target/myweb*.war target/newapp.war'
}
stage('SonarQube Analysis') {
def mvnHome = tool name: 'maven3', type: 'maven'
withSonarQubeEnv('sonar') {
sh "${mvnHome}/bin/mvn sonar:sonar"
}
}
stage('Build Docker Image'){
sh 'docker build -t rajcloud12/myweb:0.0.2 .'
}
stage('Docker Image Push'){
withCredentials([string(credentialsId: 'dockerPass', variable: 'dockerPassword')]) {
sh "docker login -u rajcloud12 -p ${dockerPassword}"
}
sh 'docker push rajcloud12/myweb:0.0.2'
}
stage('Nexus Image Push'){
sh "docker login -u admin -p admin123 43.205.239.155:8082"
sh "docker tag rajcloud12/myweb:0.0.2 43.205.239.155:8082/raj:1.0.0"
sh 'docker push 43.205.239.155:8082/raj:1.0.0'
} stage('Remove Previous Container'){
try{
sh 'docker rm -f tomcattest'
}catch(error){
// do nothing if there is an exception
}
stage('Docker deployment'){
sh 'docker run -d -p 8090:8080 --name tomcattest rajcloud12/myweb:0.0.2'
}
}
}
(Before pasting the code change the GitHub repo, docker login ID)
Build Project , Error will show while doing Docker image
chmod 777 /var/run/docker.sock
OUTPUT: SonarQube
OUTPUT: Nexus
OUTPUT: JENKINS- CI/CD Pipeline (using Blueocean)
OUTPUT: Final Application Output
instance ip:8090/newapp