ππ/ππ π£ipelines πor π‘π’ππππ¦ πull π¦tack πpplication
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