Web deployment by integrating Github, Jenkins and Docker

Task Description:-

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 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. 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.

For creating this setup we need a linux os with docker engine running on the top of it.

Let us start step by step.

Step 1:-

In this step we need to create container image that’s has Jenkins installed using Dockerfile.

So here I am using centos as image to create container image that’s has Jenkins installed.

Build the image using the command

docker build -t jenkins:v1 .

Step 2:-

In this step we have to launch a container from jenkins:v1 image and also it should automatically starts Jenkins service in the container.

Launch the container using the command

docker run -it privileged -v /:/host -p 8081:8080 — name jenkinsos jenkins:v1

We need to setup jenkins:

Step 3:-

Now we need to create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins .

Let’s craete job1

Job1 : Pull the Github repo automatically when some developers push repo to Github.

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 ).

Here in my case I have a php webpage. So I am using a webserver:v1 image which has apache webserver, php software already installed.

Job3 : Test your app if it is working or not

Job4 : if app is not working , then send email to developer with error messages.

For sending the mail I am using a python code which is their in jenkins image. So if app will be not working then the code will get executed and it will notify the developer.

Here is the output of my build pipeline.

This is the mail I get when there was an error in the code and the site was not working.

Step 4:-

We need to create one extra job for monitoring.

Job 5: This job is for monitor the container where app is running If it fails due to any reason then this job will automatically start the container again.

Here is the console output of Job 5

Here is the screenshot of two containers running with jenkins and webserver.

Thank You !!