Automate complete deployment process by building Pipeline through Jenkins + Github + Docker

Automate complete deployment process by building Pipeline through Jenkins + Github + Docker

Agenda of Project :

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 all the jobs using build pipeline plugin in Jenkins 

4. Job1 : Pull the Github repo automatically when some developers commit repo in Git.

5. Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter install 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. Job5 : if app is working, then merge the branches and create job6 which will launch new container with working app.

9. Create One extra job job7 for monitor : If container where app is running. Fails due to any reason then this job should automatically start the container again

Description :

1 . First we have to create image that’s has Jenkins installed using Dockerfile and when we launch this image, it should automatically starts Jenkins service in the container. This i already done please have a look at it.

We have to deploy the website for this we have to first create code in one of the folder this is job of developer.

Almost all the below commands for creating website and uploading the code on Github i explained in my previous article in detail.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

This step i added in this article so as soon as developer commit the code automatically it will be push at remote place. And here curl is Jenkins link and when this link someone hit automatically particular Jenkins job will be trigger having token that we used here i.e i used "jenkins" here you can use any token. If you are facing any error use below command.

No alt text provided for this image

This command "chmod +x post-commit" will make command executable written in .git/hooks/ folder.

Now let's create a job chain of all the jobs using build pipeline plugin in Jenkins 

Job1 : Pull the Github repo automatically when some developers commit repo in Git.

No alt text provided for this image

Downloading the code from testing branch of Github as have to test the code before uploading on production environment where client have access.

No alt text provided for this image

The downloaded code we are storing it into one folder name "/jenkins/". After this job2 will be trigger.

Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).

No alt text provided for this image
No alt text provided for this image

Here this job should automatically identify the type of code that developer commit. For this i used grep command which will identify the extension of the code file and based on that this job will choose the respective image for code. Function mydeployfun() will run once it call and it will launch the expose container mounted with code file. After this job3 will be trigger.

Job3 : Test your app if it is working or not.

No alt text provided for this image
No alt text provided for this image

We already deployed the code on respective container because we have to test the code working or not. So this Job will do it for us. This curl command will check website running or not and give the status code which would be store it into status variable and if value in status is 200 then we will pass this job by giving exit 0 and if value in status is not 200 means website is not working so we will fail the job by giving exit 1. And if job fail's notification mail will be send to the given email address. And it don't fail then job5 will be trigger.

Job5 : if app is working, then merge the branches and create job6 which will launch new container with working app.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

This time app/website has been deployed at production environment so client can access it but we don't have to worry because code already has been checked.

Create One extra job job7 for monitor : If container where app is running. Fails due to any reason then this job should automatically start the container again

No alt text provided for this image

To monitor our production container we will run this job after every minute for that we have to five 5 star.

No alt text provided for this image

If container goes down then it will launch new one within a second with the help of Docker.

Build Pipeline

No alt text provided for this image

This is how we can automate the complete deployment process.

Thank you to read this article. Any query or suggestion's are welcomed : )



要查看或添加评论,请登录

Omprakash Choudhari的更多文章

社区洞察

其他会员也浏览了