Development Environment using GIT + JENKINS + DOCKER

Here I have created a dummy real world development environment Integrated with GIT + GITHUB + JENKINS + DOCKER

I have created 3 jobs in jenkins which servers 3 different tasks:

Job 1 : testing environment

This job servers the task of pulling the code from github test branch and runs on the testing environment.

The code under build is:

sudo cp * /root/test_env
if sudo docker ps | grep web_test
then
echo "already running"
else
sudo docker container run -dit -p 8082:80 -v /root/test_env/:/usr/local/apache2/htdocs/ --name web_test httpd 
fi

Job 2 : production environment

The code under build is:

sudo cp * /root/production_env/
if sudo docker ps | grep web_prod
then
echo "already running"
else
sudo docker container run -dit -p 8081:80 -v /root/production_env/:/usr/local/apache2/htdocs/ --name web_prod httpd 
fi

Explanation

The job 1 and 2 are similar the difference is job 1 deals with test environment and job 2 deals with production/main environment.

Under Source Code Management we typed our repo url and selected the branch(test/master) we needed.

Then under Build Triggers we selected Poll SCM and gave schedule to our job to check the repo every minute as any changes have happened in repo the job will run automatically.

Moving on to Build we executed a shell script/command which copies the pulled code from github test/master branch and deploys into a docker container (in our case docker container is our environment).

You have noticed in Build that ports given are different, it is obviously because we have created a testing environment same as our production one and two keep them separated we gave different ports and names and due to some other stuff too.

Job 3 : branch merge and final push

This job 3 is manually conducted task done by the QAT (Quality Assurance Team) after assuring all the things are working properly or not.

When QAT is confidant then they run the job 3 and this job 3 task is to merge the test branch to the master branch and deploy it to the production environment.

Demonstration

Here is a quick demonstration of above task:

Demonstration

This is repo though is not much of a use: https://github.com/mykg/test-prod-deploy.git

Leave a comment

Design a site like this with WordPress.com
Get started