DEVOPS AUTOMATION CI/CD PIPELINE

Optimizing your CI / CD Pipeline using GitHub, Docker and Jenkins : DevOps Project(MLOPS Training)

: Anirudhi Thanvi

The article helps you to understand the basic process and line of work to implement CI/CD Pipeline through GitHub, Docker and Jenkins. Here we will undergo 3 main jobs described as below:

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

Let’s first understand the basic terminology before using in them our project.

GitHub : GitHub is designed as a Git repository hosting service, but it adds many of its own features. It is exclusively cloud based and provides a Web-based graphical interface. Here you can share your code with others, giving them the power to share and edit the code. While Git is a command line tool and is installed and maintained on your local system (rather than the cloud). Git is high quality version control system.

Docker : Docker is a tool designed to perform operating system-level virtualization, also known as containerization. Docker makes it easier to create, deploy, and run applications using containers. It allows independence between applications, environments, infrastructure, and developers.It is a fast and consistent way to accelerate and automate the shipping of software.It saves developers from having to set up and configure multiple development environments each time they test or deploy.

Jenkins : Jenkins is a open source CI/CD tool i.e. continuous integration/ continuous delivery tool. It is used to integrate and automate your product development and testing processes. The purpose of using this tool was to build and test project continuously. In an ascent of agile, this could help developers to integrate the changes to the project as quickly as possible and obtain fresh builds ready for testing.

Pre-requisites Required and Setup for project:

  1. Oracle Virtual Box
  2. RedHat Linux RHEL8
  3. Docker Installed and Configured on Your System.
  4. Jenkins Installed and Setup on Your System.
  5. Git Installed on Your System.

Environmental Setup:

  1. To start the docker services : systemctl start docker
  2. To connect to web server : systemctl start httpd
  3. To restart httpd services : systemctl restart httpd
  4. To start jenkins servies : systemctl start jenkins
  5. Incase of any Firewall interruption : systemctl stop firewalld

Let’s move on to the implementation part when you are ready with your full setup.

Step 1 : If Developer push to dev branch then Jenkins will fetch from dev and deploy on dev-docker environment.

Here we have created job 1 named as Task1 — Github-Downloading.

Execution Cell :

sudo cp -rvf * /var/www/html/
if sudo docker ps -a | grep dbos
then
echo “already running”
else
sudo docker run -dit -p 8484:80 -v /var/www/html/:/usr/local/apache2/htdocs/ — name dbos httpd
fi

Whenever developer will push any new code in the github repo. this job will download the code automatically.

Step 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.

Here we have created job 2 by name Task1 — Deploy-MasterBranch.

Execution Cell:

if sudo docker ps -a | grep dbos
then
echo “Welcome”
else
sudo docker run -dit -p 8282:80 -v /root/mlops/task1_test/:/var/www/html/ — name testos httpd
fi

Step 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.

Here we have created our job 3 by name Task1 — MergeBranch which will merge both the branches and trigger job 2.

Congratulations !!! We have finally created are First task of Automating CI/CD Pipeline Using Github, Jenkins, and Docker. And Final Outlook of are created pipeline looks like :

Our Automated Pipeline is ready which works on a single commit of the developer. For step by step process every job here is illustrated by several snapshots.

Be Somebody Nobody Thought You Could Be