Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

rutikdevops/DevOps-Project-4

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevOps-Project-4

In this project, we will explore how to set up a Jenkins CI/CD pipeline using Github, Sonarqube, and Docker on an AWS EC2 instance. Docker Host (1)

Project Blog link :-

https://medium.com/@rutikdevops/devops-project-4-31891d829c00

Project Overview :-

  • In this project I will create an AWS EC2 instance and install Jenkins on it. We will then set up a Github repository and integrate it with Jenkins. Next, we will configure Sonarqube to analyze code quality in our Github repository. Finally, we will create a Docker image of our application and deploy it using Jenkins.

Project Steps :-

  • Create 3 ec2 instance :
  1. Jenkins-Server : AWS Linux-2, t2 micro
  2. Docker-Server : AWS Linux-2, t2 micro
  3. SonarQube-Server : AWS Linux-2, t2 medium
image

1. Install and Configure the Jenkins :-

ec2-user
sudo su
yum update -y
hostnamectl set-hostname jenkins
bash
  • Java installation on Jenkins server:-
yum install java* -y
java --version
alternatives --config java              ## Using this command you can choose any version of Java
                                        // select java 11 version
  • Jenkins installation on Jenkins server:-
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
yum install jenkins -y
systemctl enable jenkins.service
systemctl start jenkins.service
systemctl status jenkins.service
  • Copy public ip of jenkins server and paste it in new tab with port no.8080
image

  • copy this path and paste in terminal with "cat" command
cat /var/lib/jenkins/secrets/initialAdminPassword
  • Now copy & paste this passwd in jenkins. so, jenkins is ready.

2. Run the code in jenkins:

  • Jenkins-> New Item-> Freestyle Project-> Source Code Management-> Git image

  • Connect github to jenkins through webhook

image

  • Build Now in Jenkins image

3. Run sonarqube

ec2-user
sudo su
yum update -y
hostnamectl set-hostname sonarqube
bash
  • Java installation on Jenkins server:-
yum install java* -y
java --version
alternatives --config java              ## Using this command you can choose any version of Java
                                        // select java 11 version
cd /opt
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.10.61524.zip  #(chrome-downloadsonarqube-latestversion-rightclick-copypaste)
unzip sonarqube-8.9.10.61524.zip
cd sonarqube-8.9.10.61524
cd bin
cd linux-x86-64
./sonar.sh start
./sonar.sh status    (in that sonarqube is not running)
cd ../..
cd logs
useradd sonaradmin
chown -R sonaradmin:sonaradmin /opt/sonarqube-8.9.10.61524
pwd
cd ..
su - sonaradmin
cd /opt/sonarqube-8.9.10.61524/
cd bin
cd linux-x86-64
./sonar.sh start
./sonar.sh status
netstat -tulpn        #(command for check port)
                      #(paste public ip with :9000)
                      #(securitygroup-inboundrule-all traffic, anywhere)
                      #(username passwd bydefault is admin)



4. Connect to terminal and install docker :-

sudo su - 
yum install docker -y
systemctl start docker
systemctl enable docker
systemctl status docker
useradd dockeradmin
passwd dockeradmin
usermod -aG docker dockeradmin
vim /etc/ssh/sshd_config
 ( PasswordAuthentication yes )
systemctl restart sshd
  • Lets Integrate Docker with Jenkins

  • Jenkins -> Manage Jenkins -> Plugins -> Available -> Search for Publish Over SSH -> Install

  • Lets configure Docker in Jenkins

  • Jenkins -> Manage Jenkins -> System -> Publish Over SSH -> SSH Servers -> Add -> Give Name -> Hostname : -> Username : dockeradmin -> advanced -> enable password based authentication -> password : <password of dockeradmin -> test configuration -> Apply -> Save

  • Successfully instegrated docker with jenkins.

  • Now goto docker server

cd /opt
mkdir docker
cd docker
chown -R dockeradmin:dockeradmin /opt/docker
vim Dockerfile
FROM tomcat:latest
RUN cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
COPY ./*.war /usr/local/tomcat/webapps
 
chmod 777 /var/run/docker.sock
  • Now Create a Jenkins job to pull the code from Github , build with help of Maven and copy the Artifacts to Dockerhost.
  • Jenkins -> Dashboard ->New project-> DevOps-Project-4-> maven project-> Source Code Management-> Post-build Actions -> select Send build artifacts over SSH -> SSH Server -> Name : give name of Added SSH Server -> Source file: webapp/target/*.war -> Remove prefix : webapp/target -> Remote directory : //opt//docker -> Exec command : enter the below commands
cd /opt/docker;
docker build -t regapp:v1 .;
docker stop registerapp;
docker rm registerapp;
docker run -d --name registerapp -p 8081:8080 regapp:v1



image

image

image

image

  • Apply -> Save

Output :-

  • Lets access the tomcat server using public ip through port 8081
image

image

image

Final Output :-

image

  • In this section, we have successfully deployed the application to the Docker server and enabled CI/CD. If any changes occur in the source code, they will be automatically built and deployed to the server.

Project Reference :-

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.