GitHub +Jenkin+ Docker Integration

Tanmay
4 min readMay 31, 2021
This project is based on Integration of Github over jenkins using docker image httpd for automation purpose.

Jenkins Task 1

JOB#1
If Developer push to dev branch then Jenkins will fetch from dev and deploy on dev-docker environment.
JOB#2
If Developer push to master branch then Jenkins will fetch from master and deploy on master-docker environment. both dev-docker and master-docker environment are on different docker containers.
JOB#3
Manually the QA team will check (test) for the website running in dev-docker environment. If it is running fine then Jenkins will merge the dev branch to master branch and trigger

Built with:
> RedHat Linux Version 8
> Docker
> Git Bash
> Jenkins

Pre-requisites:

1.OS: Base OS is Windows 10. Server OS is RedHat Enterprise Linux 8 (RHEL8) in Virtual Box.

2.In RHEL8 some of the software needed is Docker (also need the httpd image downloaded in it), Jenkins (also GitHub plugin should be installed in it), ngrok program.

<docker pull httpd>
<unzip ngrok.tar.gz>

3.In Windows, we have to install git bash software.

4.At the start stop the firewall in RHEL8 and start the docker and Jenkins services.

<systemctl stop firewalld>
<systemctl disable firewalld>
<yum install jenkins>
<yum install java>
<yum install httpd>

Step by Step Process for Automation:

Step 1. Giving Jenkins all the power of Linux :

For running Jenkins with RHEL8, You can face some permission errors like for credentials or writing or reading files that’s why to edit the sudoers file using: `gedit /etc/sudoers in your RHEL8. Add the highlighted lines i.e jenkins (ALL: ALL) NOPASSWD: ALL`.

Step 2. Necessary git commands to run inside the git bash app:

Make a directory to clone your repository using below commands

<mkdir Automation>
<cd Automation/>
<git clone “https://github.com/Tanmay4443/docker-integration-jenkins.git"

Creating a master branch and commit changes over the same

Checkout from master and commit from developer are/zone

Git command for commits, push an switching branches
<git checkout master>
<git log — online>
<git merge “new_branch_name”>
<git branch “new_branch_name”>
<git rebase>

Step 3. Creating the developer Job in Jenkins :

This job is for the Developer Unit and hence this Job will pull the data from the master branch and store it, Jenkins will fetch the developer and deploy the server using docker by using shell commands automatically.

Setting up the git repository on our Jenkins dashboard by using config Jenkin item, Enter Repository URL for your GitHub repo inside SCM.

configure Build Triggers by using POLL SCM and select 5 stars for running environment by each minute each star depicts time keywords

This is the main job inside Jenkins to make environment to work automatically, Edit below code inside Execute Shell to configure the docker environment inside RHEL8 it shows if the server is running then it will print Production server already running otherwise it will create a new server using httpd docker container:

if sudo docker ps | grep production_server
then
echo “Production server already running”
else
sudo docker run -d -t -i -p 8081:80 -v /production:/usr/local/apache2/htdocs/ — name production_server httpd
fi
sudo cp -r -v -f * /production/

Step 4. Creating the Tester Job in Jenkins :

start to build your second job on Jenkins. Note that, This job is for the Tester Unit and If Developer push to master branch then Jenkins will fetch from master and deploy on the master-docker environment. Hence, Tester will test the tammy and the master will make the necessary deployment by running the new tester server.

Setting up the git repository on our Jenkins dashboard by using config Jenkin item, Enter Repository URL for your Github repo inside SCM

configure Build Triggers by using POLL SCM and select 5 stars for running environment by each minute each star depicts time keywords

This is the main job inside Jenkins to make environment to work automatically, Edit below code inside Execute Shell to configure the docker environment inside RHEL8 it shows if the server is running then it will print Production server already running otherwise it will create a new server using httpd docker container

if sudo docker ps | grep tester_server
then
echo “Tester server already running”
else
sudo docker run -d -t -i -p 8082:80 -v /tester:/usr/local/apache2/htdocs/ — name tester_server httpd
fi
sudo cp -r -v -f * /tester/

Step 5. Creating the Quality Assurance Job in Jenkins to issue Certificate:

This job is the most important and here is the actual magic begins, It merge the developer and master branches by running necessary shell commands automatically, It internally runs some build projects and triggers to merge the developer and tester server.

Setting up the git repository for kaam2 on our Jenkins dashboard by using config Jenkin item, Enter Repository URL for your GitHub repo inside SCM and add username and password for credentials ad also Add merge before build

Add build other projects and Git publisher

Step 6. After successfull completion merge and rebase in Git bash App and your Server is running

Step 7. Tunneling for Webserver:

The Testing can check the website without having IP of the RHEL , Simply do tunneling for the same

use ngrok for tunneling

<./ngrok http 8081>

Thank you for giving Great time

~Tanmay Pathare

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response