Integration of Github with Docker and Jenkins

Problem Statement:-

Job1: If Developer push to dev branch then Jenkins will fetch from dev and deploy on the dev-docker environment.

Job2: If Developer push to master branch then Jenkins will fetch from master and deploy on the master-docker environment. both dev-docker and master-docker environments are on different docker containers.

Job3: QA team will check (test) for the website running in the dev-docker environment. If it is running fine then Jenkins will merge the dev branch to master branch and trigger #job 2

Configuration of System for integration:-

  1. run cmd systemctl stop firewalld to stop the firewall.

3. Go and change SELinux configuration and run cmd vim /etc/selinux/config and change into SELINUX=premissive mode

4. Now we change the permission of Jenkins so that Jenkins has the power of root to execute any cmd in the Linux. For that, we run the cmd vim /etc/sudoers and add new line jenkins ALL=(ALL) NOPASSWD:ALL in line no 102.

5. Your Linux should have the git software. For this use cmd yum install git.

6. You have an httpd image in your Docker. For that use, cmd docker pull httpd. For checking the image use docker images cmd.

Job1:-

We create the Developer branch and move inside it. Now we edit a file, name web.html. And push it into the GitHub using git push commands.

then push code is automatically upload into the git repository in the developer branch. And in GitHub, we set the webhook which automatically triggers the task as soon as the developer pushes the code form the gitbash of its local computer. Here we configure the webhooks and Jenkins. where webhook trigger Jenkins and copy the code from Github and deploy it into the docker using httpd docker image.

Go inside the repository setting option of git and select the webhook.
select the option as above selected

a.) create the job1 in the Jenkins and select the freestyle job in it.

b.) select the trigger according to your need. I am selecting a Github hook trigger. It automatically informs Jenkins as soon as any push has done from the developer side.

c.) Here we put the instruction which was performed by the Jenkins into the Linux os to run the job. We create one directory which contains the code which is pushed by the developer and copy inside it. Now we launch one docker image and mount this folder into the /usr/local/apache2/htdocs folder. And expose our docker so that it has outside connectivity.

d.) If our website returns the status code 200 then we will trigger the merge task which merges our developer branch into the master branch.

Job2:-

Here we create the job 2. In this job as soon as Developer push code into the master branch Jenkins automatically downloads the code from the git and launch separate docker container and deploys inside it.

code is uploaded in the master branch of git repo as soon as the push is done.

Here the role of Jenkins comes in play. we create the job2 which launches the container in the Linux which hosts our website in the real world.

Job3:-

Here we create job 3 in Jenkins which performs the merge operation of the developer and master branch.

exit 0 tells Jenkins that the job is successful

Here post-build action launches the master job after the merge operation happened.

Before merge

After merge

B.Tech student and Researcher. Like To Study And Publish Article Related To New Technologies.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store