COMPLETE AUTOMATION OF WEB DEPLOYMENT USING GIT, JENKINS & DOCKER
Prerequisite:
- GIT need to be installed in your system.
- Github plugin installed in Jenkins .
- Docker need to be installed in your system.
Problem Statement:
In this problem statement developer team create two branches (master branch and feature branch(dev)) for maintaining the master code safely. Developer team creates the code in the feature branch & after the testing, if it is working correctly then we merge the feature branch with that of master branch.
We need to create three jobs that will lead us to our result:
JOB#1
If Developer push to dev branch then Jenkins will fetch from dev and deploy on tesing Team Environment(docker environment).
JOB#2
If Developer push to master branch then Jenkins will fetch from master and deploy on master docker environment(Production Environment). Both Testing Team Environment and Production Environment are on different docker containers.
JOB#3
Manually the QA team will check (test) for the website running in Testing Team Environment. If it is running fine then Jenkins will merge the dev branch to master branch and trigger job 2.
Solution:
Here I have installed GIT in my windows & Jenkins & docker in my RHEL8 system. Here we can initialize the repo either using the git init command or by git clone command. Here I use the post-commit file that will upload the file in the github repo as developer commit the code. Code for post-commit file is :
#!/bin/bash
git push
JOB1:
When the Developer writes a code in the developer branch on his local Git repository and push the code into Github then jenkins download the code and deploy it on the QA testing team Environment on docker. Here I use the Poll SCM that will check the githuub repo in per minute basis.
JOB2:
Create the docker environment for the client side for seeing any changes in the Master branch, these change are carried out by job3. Here we use Poll SCM that will monitor the master branch on per minute basis as soon as developer commit the code.
JOB3:
If developer code is correct in feature branch according to the testing team then job3 will trigger. The job3 will merges the developer changes in feature branch with the Master branch.
Understand the whole process of the automation :
Now as soon as developer commit the code in feature branch, it will automatically push to the github repo. Jenkins will start the job1 & run the docker container on 8082 port number. Now the job1 will trigger the job3 that further trigger the job2 if it is build successfully. Also it will merge with the master branch. Job2 work is to run the container on 8081 port.
We will get the final result as shown below.
Thank You!
Github URL:
https://github.com/prashant1529/devops8