100% found this document useful (1 vote)
152 views35 pages

Capstone Project - Insurance Domain

The document outlines a DevOps certification project titled 'Insure Me', which involves using various tools such as Git, Jenkins, Docker, Ansible, Selenium, and AWS to implement a continuous integration and deployment pipeline for an insurance application. Key steps include setting up EC2 instances, installing necessary software, creating a Jenkins pipeline for building and testing code, and deploying the application using Docker containers. The project also includes configuring a GitHub webhook to automate builds upon code changes.

Uploaded by

B13 1039
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
152 views35 pages

Capstone Project - Insurance Domain

The document outlines a DevOps certification project titled 'Insure Me', which involves using various tools such as Git, Jenkins, Docker, Ansible, Selenium, and AWS to implement a continuous integration and deployment pipeline for an insurance application. Key steps include setting up EC2 instances, installing necessary software, creating a Jenkins pipeline for building and testing code, and deploying the application using Docker containers. The project also includes configuring a GitHub webhook to automate builds upon code changes.

Uploaded by

B13 1039
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DevOps Certification Training

Certification Project – Insure Me


Insurance Domain

Submitted by - Saransh Vijay Vargiya


Submitted to – Staragile
Last date of submission - 20/12/24
Objective:

In this project we will be using this tools for this


purposes
- Git - For version control for tracking changes in the
code files
- Jenkins - For continuous integration and continuous
deployment
- Docker - For deploying containerized applications
- Ansible - Configuration management tools
- Selenium - For automating tests on the deployed web
application
- AWS : For creating ec2 machines as servers and
deploy the web application.
- Let us create three Ec2 instance of type.
[Link]
OS – ununtu 22

- Now connect the machines using the mobaxterm.


- Now on the ansible controller machine use this
commands to install aansible.
# sudo apt-get install -y software-properties-
common
# sudo apt-add-repository ppa:ansible/ansible
It will ask for Press [ENTER] to continue or Ctrl-c to
cancel.
Now press enter key on your keyboard

# sudo apt-get update


# sudo apt-get install -y ansible
- Use the command
# ansible –version
To check the version of the ansible.

- Create a new user on the terminal:

# adduser ansiuser

Enter New password : ansiuser


Retype new Password: ansiuser

Don’t enter any value for fullname, room number,


workphone, homephone other
Just keep pressing enter key.
And give Y for
Is the information correct ? [Y/n] : y

- User will now be created.

Add ansiuser in sudoers files and give all permission


# vim /etc/sudoers
Press i
Scroll down until your find : # User privilege
specification
Now enter below line under 🡺 root ALL=(ALL:ALL) ALL
ansiuser ALL=NOPASSWD: ALL
- Generate SSH key on Master machine and copy
SSH key on worker machine
- All These Steps will be executed on Master
Machine only
Step 1:
Change user from root to ansiuser
# su - ansiuser

Step 2:
Generate ssh key on Master node for ansiuser
Execute below command:
# ssh-keygen

press enter
press enter
press enter

ssh key will be generated


- Steps to be executed on Worker Node:
=======================================
# sudo su -
Create a new user on the terminal:
# adduser ansiuser
Enter New password : ansiuser
Retype new Password: ansiuser
Don’t enter any value for fullname, room number,
workphone, homephone other

Just keep pressing enter key.


And give Y for
Is the information correct ? [Y/n] : y
User will now be created.
We will give sudo permission to this user so that it can
execute linux commands without need of password

Add ansiuser in sudoers files and give all permission


# vim /etc/sudoers
Press i
Scroll down until your find : # User privilege
specification
Now enter below line under 🡺root ALL=(ALL:ALL) ALL
ansiuser ALL=NOPASSWD: ALL
Now switch to ansiuser on worker node and create .ssh
folder

# su - ansiuser

# mkdir .ssh

Go to master node(devops lab) and copy the ssh public


key of ansiuser

# cat /home/ansiuser/.ssh/id_rsa.pub
Paste it on the worker nodes
# echo "<give your public key>" >>
~/.ssh/authorized_keys

Now we can connect to both the workers using the


controller machine

Worker2
Worker1

Press exit to close the worker sessions


- Now in the controller machine create a inventory
file and add the private ip address of all the worker
machines

- Now let us see that our controller and worker


machine are responind to each other
- Use the command
#ansible -I /home/ansiuser/myinventory webserver -m
ping
Step 2: Install all the tools for CICD

Go the us-east-1 region:

Please connect to the newly created EC2 instance


which has Ansible installed on it -> We can call this
instance as Ansible Controller.
[make sure its instance type is [Link] because we
have to setup Jenkins, docker, monitoring tools on this]

Connect using EC2 instance connect


Check if ansible is installed:
# ansible --version
# sudo su –
Run the below commands for installing Jenkins:
[Always take the lastest steps for Jenkins]

Add Jenkins key to the server


# sudo wget -O /usr/share/keyrings/jenkins-
[Link] [Link]
stable/[Link]
Make Jenkins apt repo
# echo "deb [signed-by=/usr/share/keyrings/jenkins-
[Link]]" [Link]
binary/ | sudo tee /etc/apt/[Link].d/[Link] >
/dev/null

Create a playbook with below code


# vim [Link]
- name: Install and set up devops tools
hosts: localhost
become: true
tasks:
- name: Update the apt repo
command: apt-get update
- name: Install multiple packages
package: name={{item}} state=present
loop:
- git
- [Link]
- openjdk-17-jdk
- name: update apt-repo
command: sudo apt-get update
- name: install jenkins
command: sudo apt-get install jenkins -y
- name: start Jenkins and docker service
service: name={{item}} state=started
loop:
- jenkins
- docker
Save the file and run it

# ansible-playbook [Link]

Now check for Jenkins, docker versions


Step 3: Continuous Integration pipeline
=============================================
=============
Setup Jenkins dashboard and login to the Jenkins
Dashboard.
Setup maven in tools section of Jenkins.

Create a Pipeline code to fetch code form github and


test and build the code using maven commands.

pipeline{

agent any

tools{
maven 'mymaven'
}
stages{
stage('Clone Repo')
{
steps{
git
'[Link]
[Link]'
}
}
stage('Test Code')
{
steps{
sh 'mvn test'
}
}

stage('Build Code')
{
steps{
sh 'mvn package'
}
}

}
}

Step 4: Containerize and implement microservice


architecture

We will write a dockerfile and save it in the github repo

FROM openjdk:11
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} [Link]
EXPOSE 8081
ENTRYPOINT ["java","-jar","/[Link]"]

We will go to the CICD pipeline in Jenkins add a stage to


build dockerfile in to an Image

We will run the image to deploy application on


container.

Before running the pipeline, go to the terminal of VM


and execute this command:
This command will allow Jenkins to run docker
commands
# chmod -R 777 /var/run/[Link]

pipeline{

agent any

tools{
maven 'mymvn'
}

stages{
stage('Clone Repo')
{
steps{
git '[Link]
vijayvargiya/[Link]'
}
}
stage('Test Code')
{
steps{
sh 'mvn test'
}
}

stage('Build Code')
{
steps{
sh 'mvn clean package'
}
}
stage('Build Image')
{
steps{
sh 'docker build -t
myinsurance:$BUILD_NUMBER .'
}
}

stage('Push the Image to dockerhub')


{
steps{

withCredentials([string(credentialsId:
'DOCKER_HUB_PASWD', variable:
'DOCKER_HUB_PASWD')])
{
sh 'docker login -u saranshvijayvargiya -p
${DOCKER_HUB_PASWD} '
}
sh 'docker tag myinsurance:$BUILD_NUMBER
saranshvijayvargiya/myinsurance:$BUILD_NUMBER '
sh 'docker push
saranshvijayvargiya/myinsurance:$BUILD_NUMBER'
}
}

}
}
With this code we have created the image and pushed
the image to the docker hub
Go to the terminal attach 2 worker nodes to ansible
controller which we already did
Create inventory file on the ansible controller
Now create a file in the git repository with the name
[Link]
And save this code in there
- name : Configure Docker on EC2 Instances
hosts : all
become: true
tasks :
- name: updating apt
command : sudo apt-get update

- name : Install Docker


command : sudo apt-get install -y [Link]
become : yes
become_user : root

- name : Start Docker Service


command : sudo systemctl start docker
become : yes
become_user : root
- name: Deploy Docker Container
command: docker run -itd -P <ImageName>

This is the final pipeline code


pipeline{

agent any

tools{
maven 'mymvn'
}
stages{
stage('Clone Repo')
{
steps{
git '[Link]
vijayvargiya/[Link]'
}
}
stage('Test Code')
{
steps{
sh 'mvn test'
}
}

stage('Build Code')
{
steps{
sh 'mvn clean package'
}
}
stage('Build Image')
{
steps{
sh 'docker build -t
myinsurance:$BUILD_NUMBER .'
}
}

stage('Push the Image to dockerhub')


{
steps{

withCredentials([string(credentialsId:
'DOCKER_HUB_PASWD', variable:
'DOCKER_HUB_PASWD')])
{
sh 'docker login -u saranshvijayvargiya -p
${DOCKER_HUB_PASWD} '
}
sh 'docker tag myinsurance:$BUILD_NUMBER
saranshvijayvargiya/myinsurance:$BUILD_NUMBER '
sh 'docker push
saranshvijayvargiya/myinsurance:$BUILD_NUMBER'
}
}
stage('Configure and Deploy to the Test Server') {
steps {
ansiblePlaybook(
become: true,
credentialsId: 'ansible-key',
disableHostKeyChecking: true,
installation: 'ansible',
inventory: '/etc/ansible/myinventory', // Or you
can use a dynamic inventory here
playbook: '[Link]',

)
}
}
}
}

Now check the worker machine for the containers


Now copy the worker nodes ip address and paste it
along with the port 8084 to access the application on
the internet.
Now let us create a github webhook so that when ever
there is a change in the code it will automatically start
creating a new build for it.
Goto jenkns dashboard > your project >configure >
select GitHub hook trigger for GITScm polling.
Now move back to the git repository >setting >
webhooks > add webhook.

And click on create web hook


Now we have successfully deployed our code using the
mentioned tools.

You might also like