Production & Testing Automation using Docker, Git, Jenkins

Aim : As soon as a developer makes some changes (or commits in Git for the website) it is automatically send to the QA-team , after their approval then only changes will be reflected to the main website.

Three jobs to be done:

Job1: If developer push the code from master branch then Jenkins will fetch from master and deploy to production_team webserver (created using docker).

Job2: If developer push the code from dev_branch(other than main) then jenkins will fetch from dev_branch and deploy on testing_team webserver (created using docker).

Job3: QA-team will test the new code , if it is running fine then Jenkins will merge dev_branch with the master branch. and triggers job1.

Setting up server system:

No alt text provided for this image

Creating two directories :

-Stop firewall and selinux:

systemctl stop firewalld


setenforce 0

Start docker and Jenkins services:

systemctl start docker

systemctl start jenkins

Setting up Github

Create a new repository.

No alt text provided for this image

Now go to developer side :

No alt text provided for this image
notepad .git/hooks/post-commit (Create hooks)

 #!/bin/bash
  git push       ( To automatically push as soon as you commit.)

cat > index.html ( new page created add data and press ctrl + D to save)

git add .        ( to stage)
git  commit . -m " first commit"   ( will be uploaded to git automatically)


git push --set-upstream origin solaris (Sync if not)
No alt text provided for this image
No alt text provided for this image

Create newbranch(dev_branch).As soon as you edit the code in dev_branch and add commit its is automatically uploaded to github(dev_branch).

Jenkins set up:

  1. Install github plugin. Click on new Item and create job as follows:

Production_job configure:

No alt text provided for this image

Click on configure:

No alt text provided for this image

You can also use triggers to automate more faster as compare to Poll SCM.

No alt text provided for this image
No alt text provided for this image

CODE:

No alt text provided for this image

Testing_job configure:

select dev_branch
No alt text provided for this image
No alt text provided for this image

CODE:

No alt text provided for this image

QA-team configure:

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

CONCLUSION:

No alt text provided for this image

As soon as developer made changes and commits.

(“New changes made by developer”)

Jenkins automatically does his job.

No alt text provided for this image
No alt text provided for this image

First do testing_job >>QA-team-checking>>Production_job

And at the main website new changes uploaded after following the procedure.

No alt text provided for this image

And at the server: Two server created using docker (httpd) automatically by the Jenkins.One for the production team and other for testing team.

No alt text provided for this image

**We can also trigger Jenkins using github-hooks in github this will be create more fast automation.**

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s