Basic CI/CD Pipeline using Jenkins + Git + Docker.

Basic CI/CD Pipeline using Jenkins + Git + Docker.

In this article I will show you how to implement a basic CI/CD pipeline with the help of very useful tools like Jenkins, Git and Docker.

Prerequisites for the task:

The task is discussed keeping in mind that Git, Jenkins and Docker have already been configured in your system. So if you haven't done this yet, I highly suggest that you complete the configuration before commencing the task.

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.

Solution Overview:

JOB-1: In this step, the developer makes the required changes to the files in the local repository and pushes contents into the dev branch of the VCS (here GitHub).

Once this happens, the Job1 of Jenkins is responsible to download the contents from GitHUb onto the server system. The job configurations are as follows:

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

The shell command is as follows:

sudo cp -v -r -f * /lwweb
if sudo docker ps | grep mydockerweb
then 
echo "already running"
else
sudo docker run -d -t -i -p 8082:80 -v /lwweb:/usr/local/apache2/htdocs/ --name mydockerweb httpd
fi

JOB-2: In this step, the developer makes the required changes to the files in the local repository and pushes contents into the master branch of the VCS (here GitHub).

Once this happens, the Job2 of Jenkins is responsible to download the contents from GitHub onto the server system. The job configurations are as follows:

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

The shell command is as follows:

sudo cp -v -r -f * /lwweb_prod
if sudo docker ps | grep mydockerweb_prod
then 
echo "already running"
else
sudo docker run -d -t -i -p 8083:80 -v /lwweb_prod:/usr/local/apache2/htdocs/ --name mydockerweb_prod httpd
fi

JOB-3: This job forms the bridge between Job1 and Job2. Here the dev branch is merged with the master branch when there is no testing failures in the developer version of the code. The configurations of this job are as follows:

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

The final pipeline outlook is shown below:

No alt text provided for this image

GitHub link: https://github.com/krishsabnani/dockerweb.git

Hope this article was helpful for you.

Thanks for reading!



To view or add a comment, sign in

More articles by Krish Sabnani

Explore content categories