Cliff.ai DevOps Task

Nishant Saini
5 min readNov 5, 2021

Problem Statement: To create and configure a simple CI/CD pipeline using Jenkins or any other open-source automation tool.

The pipeline should be able to:

Get triggered when any new commit/merge is done to the Version Control System.

Source the code from the VCS.

Create the docker image and should update it on the machine where the deployment is live.

Solution:

To solve this task, I have used below DevOps tools/technologies:

  • Public Cloud — AWS
  • Terraform
  • Docker
  • Jenkins
  • Version Control System — Github
  • Linux Concepts

Architecture:

  • Using terraform launched one Instance in AWS Cloud, so that we can perform the task.
  • Also used terraform to install a few software like git, Jenkins, docker in that instances.
  • Created a GitHub repo that will trigger the Jenkins pipeline whenever a new push/merge happens in the repo.
  • Jenkins pipeline will be triggered by GitHub repo.
  • Upon triggering the Jenkins pipeline, it will fetch Dockerfile from GitHub repo and create Image from it and push the image to Dockerhub.

Step by Step Implementation of Task:

First of all, we will launch one EC2 instance on AWS Cloud and we will install a few software/packages in the instance.

For this purpose, I have used Terraform.

Terraform code to launch the instance on AWS cloud and install few software in that instance is given below:

The above given terraform code, will launch an EC2 instance in AWS Cloud and then install a few packages like Docker, Jenkins, git in that instance.

Few terraform Commands that are used to run this code are:

terraform init → used to download the plugins that are required to go to AWS Cloud.

terraform validate → used to validate the syntax of the terraform code.

terraform apply → used to run/apply the terraform code.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

— — — — — — — — — — — — — — — — —

The above three screenshots show that terraform code run successfully and it launch one instance in the AWS cloud.

Now, if we go to “Public-IP_OF_Instance:8080”, we will redirect to Jenkins WebUI as Jenkins runs on port 8080.

When we go to Jenkins WebUI first time, it will ask for the administrator password, we will get the administrator password of Jenkins from the “/var/lib/jenkins/secrets/initialAdminPassword” location of the O.S where Jenkins is running.

Now, we will create a Github repo that will contain Dockerfile, so that Jenkins job can build docker image from that Dockerfile and push that docker image to docker hub.

As we want that Jenkins job will always run whenever we push a new event to GitHub repo, so for this purpose, we will use “Webhooks” of Github repo.

In the above Image, I have set webhook trigger, so that we can Jenkins job automatically whenever a new push is done to Github repo.

Now, we will create a Jenkins pipeline that will automatically fetch the Dockerfile from Github repo, create Image from that repo and push the Image to dockerhub.

— — — — — — — — — — — — — — — — — — —

— — — — — — — — — — — — — — — — — — — -

— — — — — — — — — — — — — — — — — — — — —

— — — — — — — — — — — — — — — — —

The above all Images shows the Jenkins pipeline that will fetch Dockerfile from GitHub repo (whenever a new push is done to GitHub repo), build a Image from Dockerfile and push the Image to Dockerhub.

Points to Remember:

  • Jenkins user will run Jenkins pipeline and Jenkins user don't have the capability to run docker commands, so we have to give sudo powers to Jenkins user.
  • When Jenkins pipeline will push the Docker Image to dockerhub, for this Jenkins will need credentials of our docker hub account.

So we will go to Manage Jenkins → Manage Credentials and there we will add credentials of our dockerhub account so that Jenkins can push docker images to our Dockerhub account.

By doing all this setup, the required task will be solved.

For your reference:

URL where jenkins is running → http://3.110.32.57:8080/

username of jenkins account → nishant

password of jenkins account → XXXXXXX

--

--

Nishant Saini
0 Followers

RedHat Certified Engineer (RHCE) | AWS Academy Graduate | DevOps Enthusiast