DevOps | Continous Integration with GIT | DOCKER | JENKINS for web application Deployment

Documentation for Web application Automation With the Integration of Jenkins, Git and Docker




In This Tutorial we will Implement the end-to-end Automation of our Web application Using Jenkins, Docker and Git by integrating them.

Prerequisites:
  1) Jenkins 
  2) Docker
  3) Git
  4) Github account
  5) REHL v8

 I am assuming that you already have all the above requirements fulfilled . If not please check on google to how to setup Jenkins, Docker, Git and Github account and Redhat v8

Step 1:
1) Go to your Redhat OS and inside terminal start the jenkins and docker service by using following command

* systemctl start jenkins
* systemctl start docker

 2) Create a directory (You can name it anything)
 * mkdir devops-jenkins-docker-git

Step 2:
1) Go to your Github account and there create a repository you can name it anything  (devops-jenkins-docker-git)

Step 3:

1) Now in your redhat system go and clone the repo you created on your github account 

* git clone https://www.github.com/{your account name}/devops-jenkins-docker-git

2) Now we need to create a hook inside .git folder so that whenever we commit any changes it automatically gets pushed to our github repo

For that go inside your repo and then use the following command




Webhook for jenkins job trigger

* cd devops-jenkins-docker-git
* cd .git/hooks
* Edit the post-commit.sample file using mv post-commit.sample && vim post-commit 
* if you don't have that file already use touch post-commit and then vim post-commit
* Then add this line inside that file

#!/bin/bash
git push

* Now save this file

Step 4:
we need to create a new branch inside our repository that is dev1

we already have a branch known as master branch and we are creating a 2nd branch dev1. so that we will have a testing branch in which we keep our code for testing and development purpose

* git branch dev1 

 Step 5:
Now go to jenkins web UI using http://localhost:8080

First of all we need to install some plugins inside jenkins which will help us in integration with github
 
Install github plugin in jenkins by going inside manage jenkins then manage plugins

Step 6:
Now this is an important part we need to create our 1st job
There are total 3 jobs we need to create



 
 Now we need to use poll scm to check every minute the changes inside our repository



 Now create two directories 

mkdir production_code
mkdir development_code

You need to Execute the following commands inside Build section

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_code:/usr/local/apache2/htdocs/ --name
production_server httpd
fi

sudo cp -r -v -f * /
production_code/








Step 7: 

Now we need to create our 2nd job which will trigger only when our 1st job will execute successfully

 

Now we need to use poll scm to check every minute the changes inside our repository




You need to Execute the following commands inside Build section

if sudo docker ps | grep development_server  
then
echo "development server already running" 

else
sudo docker run -d -t -i -p 8081:80 -v /
development_code:/usr/local/apache2/htdocs/ --name development_server httpd
fi

sudo cp -r -v -f * /
development_code/








Setp 8:

Now we need to Create our 3rd and final job which will  merge the two branches the master branch and dev1 branch after the confirmation from QTA team


Now setup the build trigger for job2 whenever job1 is successfully
executed 


Only if job1 is successful then job2 will run otherwise not
 



That is it now we have end-to-end integration.
 
Now whenever the QAT team thinks that the code of developer in dev1 is to be used then the two branches will merge together and the changes done in dev1 will appear in master branch and will be deployed to Docker production server



If you require code then you can visit the above link and read the README.md file

Conclusion 
There are many use cases we can implement using this GIT | DOCKER | JENKINS

Github Link
  https://github.com/Moiz-Ali-Moomin/devops-jenkins-docker-git.git
 

Comments

Popular posts from this blog

Task 2 DevOps using Jenkins, Docker and git