Complete Automation of Web-Application Deployment and Testing using Jenkins, Docker and GitHub.

Complete Automation of Web-Application Deployment and Testing using Jenkins, Docker and GitHub.

TASKS:

1. Create a container image that’s has Jenkins installed using Docker File.

2. When we launch this image, it should automatically start the Jenkins service in the container.

3. Create a job chain of Job 1, Job 2, Job 3 and Job 4 using the build pipeline plugin in Jenkins.

4. Job 1: Pull the GitHub repository automatically when some developers push the repository to GitHub.

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

6. Job 3: Test your app if it is working or not.

7. Job 4: If the app is not working, then send an email to the developer with error messages.

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

SOLUTION:

I start by creating a Docker File using Centos: latest image pulled from docker hub.

No alt text provided for this image

Here installing:

1) Sudo for root powers ,

2) Wget for downloading the files from url,

3) Installing net-tools for viewing IP address( specially for ifconfig)

4) Set the yum repository for Jenkins from URLs using wget command.

5) Install java for Jenkins.

6) Created Jenkins entry in the sudoers file to give it root powers without need of any password.

7) Installed git for Jenkins .

8) Installed Python3 for mailing via python code.

After creating image by command “docker build -t name:version”

We have to run the container from this image “docker run -itd -p 1234:8080 — name hw2 — privileged name:version”

Here we have to give admin password shown in terminal (shown below)

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

Here we successfully run the image and now download all the suggested plugins first and then we can use the jenkins smoothly.

No alt text provided for this image

Now we will do the jobs as asked in the above given problem:

Job 1.

The first job is Pull the GitHub repo automatically, for this we have to do some steps as shown below..

Step 1. Click on the “Github project” in first general section and enter your github repository url in project url section.

No alt text provided for this image

Step 2. Click on the “Git” in Source Code Management section and enter github url again in repository url.

No alt text provided for this image

Step 3. Select “Github hook triggeer for GITScm polling” and in Build Environment section Select “Add Timestamps to The Console Output"

No alt text provided for this image

Step 4.In “Build” Section select the “Execute Shell” for writing code , in this code we create a repo directory if it is available then first remove it create a new web-repo directory. It’s done for Job 1. Apply and save the job.

No alt text provided for this image

Job 2.

Job 2 is simpler than previous one,

From here we are going to start a chain of job.

For this:

Step 1. We select “Build After other project are built” in “Build Triggers” section

No alt text provided for this image

Step 2. We have to write a code which will work after Job 1 built successfully and it will deploy a container(httpd container named as “ak_dep”) on the host system. It’s done.

Apply and save.

No alt text provided for this image

Job 3.

Step 1. For making chain select “Build after ..” as we did in Job 2.

No alt text provided for this image

Step 2. For testing our application we have created this job. After test fails it will go to Job 4 for mailing to developer's email address.

No alt text provided for this image

Job 4.

Step 1. As in Job 2 and Job 3 we have to create chain by selecting “build after projects are built”.

No alt text provided for this image

Step 2. We only have to write here “python3 mail.py” because we have created a python program file along with the Dockerfile. This job is created for sending the mail to developer if testing of our application got fail.

No alt text provided for this image

Job 5.

In configuration of Job 5 We only have to do 2 things one to create job/task chain and select the “Build Periodically” to schedule the interval here we have given five stars this means that we need to run this job every minute.

No alt text provided for this image

We have done the creation of jobs successfully,

All created jobs are successfully built (The blue ball shows that it is successfully built )

No alt text provided for this image

Now we have to see the results in Build Pipeline View.

No alt text provided for this image

















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

Bhavesh Sharma的更多文章

社区洞察

其他会员也浏览了