Automation using pipeline in Jenkins Image integrating with Docker and GitHub
In this task I will be developing a CI/CD pipeline which downloads the code form GitHub and deploys on respective Docker Image
Problem Statement:
1. Create container image that’s has Jenkins installed using Dockerfile
2. When we launch this image, it should automatically starts Jenkins service in the container.
3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins
4. Job1 : Pull the Github repo automatically when some developers push repo to Github.
5. Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).
6. Job3 : Test your app if it is working or not.
7. Job4 : if app is not working , then send email to developer with error messages.
8. Create One extra job job5 for monitor : If container where app is running. fails due to any reson then this job should automatically start the container again.
To solve this task I have developed my own custom docker image called "syedfaheem/jenkins:v4"
I have use the below Dockerfile for creating it
We can download the by using the below command
docker pull syedfaheem/jenkins:v4
then start the container
docker run -dit -v /root/task2:/root/mlops-task2 -p 80:14356 --name dev syedfaheem/jenkins:v3
Go to IP:14356 [Here IP is the IPAddress of the Host VM]
then go to /root/.jenkins/secrets/initialAdminPassword
docker exec -it dev bash cat /root/.jenkins/secrets/initialAdminPassword
In the above pic the highlighted is the password which is used to login
Wait for a while till the plugins gets installed
Now I will be generating the ssh key and send it to the host VM as it will be required in the task
So we have successfully sent the generated ssh key and sentit to the host VM
This will us to do ssh from the container to the host VM without using password
For Ex:
So lets start our Jobs in jenkins
JOB1
This will automatically get triggered when ever there is a change in the Git Repo and it will download the code in the folder specified
JOB2
This job will remote login into host VM and deploy the code in the required container. Here I have taken only one file (index.html)but soon will update it
So for html I will deploy it in httpd container
JOB3
The main purpose of the job is to check whether the deployment is done correctly or not. If it is not correctly done then it will notify the email recipient. Basically it does testing
JOB4
The main purpose of this Job is to monitor whether the container is running or not
Build Pipeline View
Hence we have successfully deployed the webpage
Feel free to ask any queries
Name: Syed Faheemuddin
university of Hyderabad
LinuxWOrld
email Id : [email protected]