deploying web application using Git , Docker and jenkins (CI / CD tool)

Hirendra kumar
5 min readJul 5, 2020

This is a task to deploy our web application using Git , Docker and jenkins . Using these tools we can make our task as possible as automate . it is something like that whenever developer commit their code then automatically code push to some SCM system like Github and from there jenkins pulling code and deploying it in a container.

Task description -

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 #job 2.

Pre- requisite -

In which base operating system you are working run these commands-

1. systemctl start docker — for starting docker services so that jenkins can deploy our webserver.

2. systemctl start jenkins — for starting jenkins and we can use jenkins in windows using base OS ip and port 8080 . jenkins run on port no 8080.

starting jenkins using baseOS ip

3.systemctl stop firewalld — to stop firewall

Git-

In git firstly i as a developer created a seprate folder . it is good practise to write code in a isolated folder . this folder is called workspace.

> In git we create a repository . to make that folder a repository use-

git init

> Git has a functionality to keep on tracking the files in the particuler repo . to be tracked a file use -

create folder and git init

git add

now file will be tracked by GIT . this area is alos called staging area.

> git commit command keep on doing versioning the file whenever developer changes anything or add and update file. in this way we can easily find the last code if needed because sometimes new code has some bug . so we can easily roll back to previous code.

Branch -

I created a branch named dev . it will work as testing branch for developer and IF all will be good then we merge it to master branch.

bash script for post-commit-

command after commit will run automatically using script

Using this bash script as soon as developer commits then is will automatically push to some SCM system like Github and jenkins automatically come to know from which branch they have to pull code and will deploy in respective container.

creating jobs -

job 1 -

In this job if developer push to dev branch then through bash script jenkins will go to dev branch and pull code and will deploy it into a dev enviroment (in my case devdocker).

from this URL jenkins fetch
build trigger used to inform jenkins

This build trigger we write in bash script so that jenkins come to know that any changes occur in code that developer had pushed to github.

devdocker env launched

job 2 -

in this job if developer push code to master branch then jenkins will come to master branch and will pull code and deploy.

masterdocker env laucnhed

job 3 -

in this job quality assurance team will manually check the devdocker env . if it is not upto the mark means having some issue . then developer again write code and if this time all is woring fine . then they asked him to merge the dev branch into master branch so that the workflow from now onwards go smoothly.

merging branches

if this job will successfully run then it will automatically build job 2 again and final site will come.

screenshots of sites-

testing site

above is the testing site that will be checked by quality team and after all is fine they will give approval .

this is main site through master branch.

git merge

in git merge we have sometimes conflict issue . in my case it also occur . then to remove this issue i have to cut the conflict code and after that it merged to master branch.

this is my final site after solving merge conflict issue.

Github link for code-

>> This task , i completed because of my mentor MR VIMAL DAGA sir . He teaches every thing from very basic to advance very clearly.

THANK YOU SIR !!!

#vimaldaga #preetidaga #LinuxWorld #righteducation #jenkins #git #docker

--

--

No responses yet