Basic DevOps CI/CD Pipeline

In this tutorial, we implement a basic scenario to create a DevOps  CI/CD Pipeline. First, let’s remember what should we expect from a CI/CD Pipeline.

Where is the code?
How do we build the code?
Which tests will be applied?
Where will the release process be carried out?
Where do we maintain the artifact?
How do we deploy the artifact?
How will we monitor runtime?

GitHub, Docker, JUnit, Jenkins, Ansible, DockerHub and Nagios will be our answers.

In this episode, we will set up the environment by installing Ansible, Docker, and Jenkins. Then get the code from Github to Jenkins.

We will be using an Ubuntu 20.04 virtual machine on AWS for CI/CD processes, and another Ubuntu 20.04 for application.

Installing Ansible on Ubuntu 20.04

First, we will update the apt package repository cache. Then install the latest Ansible version with apt-get, & check the version.

Then we will add the application servers detail to ansible hosts file.

apt-get update
apt-get install -y ansible
ansible --version
vi /etc/ansible/hosts
###
[appservers]
appserver1 172.31.0.4
###

Installing Jenkins on Ubuntu 20.04

First, we need to get & add the apt-key, then add the related binary to apt source list. Then install the latest Jenkins version with apt-get.

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
apt-get update
apt-get install -y jenkins
systemctl start jenkins
systemctl enable jenkins
systemctl status jenkins

After the installation, we need to access the GUI using the server’s external IP address.

curl icanhazip.com
# The output is the server's external IP

cat /var/lib/jenkins/secrets/initialAdminPassword
# The output is the Admin Password of Jenkins

# GUI address;
http://<external_ip>:8080

Then you need to navigate to the GUI and paste the admin password. And proceed with installing suggested plugins. After the plugin installation, you need to create the first admin user.

Installing Docker on Ubuntu 20.04

The fastest way to install Docker is get.docker script. After the Docker installation, we need to allow the Jenkins user to execute docker commands.

sudo curl -sSL https://get.docker.com/ | sh
systemctl start docker
sudo groupadd docker
sudo usermod -aG docker jenkins
sudo systemctl enable docker
docker version

In the next episode, we will continue by getting the source code from GitHub to Jenkins.

Then create a Docker Image with setting up the JUnit test.

Push our artifact to the DockerHub.

Preparing a deployment ansible-playbook.

Triggering the ansible-playbook within Jenkins.

Setting up the monitoring baseline.

Leave a Comment

Your email address will not be published. Required fields are marked *