π—–π—œ/𝗖𝗗 𝗣ipelines 𝗙or π—‘π—’π——π—˜π—π—¦ 𝗙ull 𝗦tack 𝗔pplication

Β·

4 min read

A step-by-step guide to deploying a NodeJS-based Application using Jenkins as a CI/CD tool.

I will be deploying a Banking NodeJS-based Application from scratch, complete with a fully-fledged backend, frontend, and database integration using Jenkins.

πŸ› οΈ Deployment Steps

πŸ”Ή Step 1 β€” Create an Ubuntu T2 Large Instance

πŸ”Ή Step 2 β€” Install Jenkins, Docker, and Trivy.

πŸ”Ή Step3 β€” Create an Instance and use mobaXterm or Putty to access the server in Windows OS

πŸ”Ή Step4 β€” Create a Pipeline Project in Jenkins using a Declarative Pipeline

πŸ”Ή Step 5 β€” Create a Sonarqube Container using Docker.

πŸ”Ή Step 6 β€” Install plugins Docker, NodeJs, JDK, Owasp, and Sonar-Scanner.

Step7 β€” Access the Real World Application

πŸ”Ή Step8 β€” Terminate the AWS EC2 Instance

Now, let’s get started and dig deeper into each of these steps:-

πŸ”Ή Step 1 β€” Launch an AWS T2 Large Instance. Use the image as Ubuntu. You can create a new key pair or use an existing one. Enable HTTP and HTTPS settings in the Security Group.

πŸ”Ή Step 3 β€” Create an Instance and use mobaXterm or Putty to access the server in a Windows machine.

πŸ”Ή Step 4 β€” Install Jenkins, Docker, and Trivy.

πŸ”Ή Step 5 β€” Create a Sonarqube Container using Docker.

To Install Trivy : (Step-2)

sudo apt-get install wget apt-transport-https gnupg lsb-release

wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /etc/apt/sources.list.d/trivy.list-o /usr/share/keyrings/trivy-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/trivy-archive-keyring.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -cs) main"https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -cs) main"

sudo apt-get update

sudo apt-get install trivy

To Install Jenkins :

sudo apt update -y

sudo apt install openjdk-11-jre -y

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo gpg --dearmor -o /usr/share/keyrings/jenkins-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/jenkins-archive-keyring.gpg]

https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null sudo apt update -y

sudo systemctl start jenkins

sudo systemctl status jenkins

Create a Sonarqube Container using Docker :

sudo apt-get update

sudo apt-get install ca-certificates curl gnupg sudo install -m 0755 -d /etc/apt/keyrings

echo \

echo "deb [arch=$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.dock

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo

"$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

sudo apt install docker-compose

service docker restart

sudo usermod -aG docker $USER

newgrp docker

sudo chmod 666 /var/run/docker.sock

sudo systemct1 restart docker

# TO INSTALL SONARQUBE USING DOCKER RUN THE BELOW COMMAND

docker run -d --name sonar -p 9000:9000 sonarqube:lts-community

I have used port 8083 to access the Jenkins.

Now, grab your Public IP Address

<EC2 Public IP Address:8083>
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Unlock Jenkins using an administrative password and install the required plugins.

#TO ACCESS SONARQUBE

<EC2 Public IP Address:9000>

Install Plugin

Goto Manage Jenkins β†’Plugins β†’ Available Plugins β†’

Install below plugins

1 β†’ Eclipse Temurin Installer (Install without restart)

2 β†’ SonarQube Scanner (Install without restart)

3 β†’ NodeJS (Install without restart)

4 β†’ Docker (Install without restart)

5 β†’ OWASP (Install without restart)

πŸ”Ή Step 7 β€” Configure the Plugins with the mentioned version.

JDK β€” 17 & 11

Docker β€” Latest

OWASP β€” Renamed as (DC) and version is Dependency-check-6.5.1

Node JS β€” Version 16

SonarQube β€” 5.0.1.3006

πŸ”Ή Step 8 β€” Grab the Public IP Address of your EC2 Instance, Sonarqube works on Port 9000, sp <Public IP>:9000. Goto your Sonarqube Server. Click on Administration β†’ Security β†’ Users β†’ Click on Tokens and Update Token β†’ Give it a name β†’ and click on Generate Token.

Click on Update Token

Now, go to Dashboard β†’ Manage Jenkins β†’ Configure System

Click on Apply and Save

The Configure System option is used in Jenkins to configure different server

Global Tool Configuration is used to configure different tools that we install using Plugins

We will install a sonar scanner in the tools.

Create a Job β€” Label it as Bank, click on Pipeline, and Ok.

Here is the Pipeline Script,

The stage view would look like this, you will see the output like below.

To check the containers use the command as docker ps.

You can see the SonarQube report has been generated and the status shows as passed.

With the help of port 3000 using public IP, we can access our Application on the web.

Access the Bank Application

Β