DevOps Project-41: Deploying Swiggy Clone with Terraform, Jenkins, SonarQube, Trivy & Docker
This end-to-end DevOps automation project demonstrates the complete CI/CD lifecycle for deploying a Swiggy clone web application onto an AWS EC2 instance. The pipeline is orchestrated by Jenkins and follows a robust DevSecOps methodology by integrating code quality scanning via SonarQube, vulnerability detection using Trivy, and containerized deployment through Docker. Infrastructure provisioning is managed entirely with Terraform, creating a production-ready automated workflow.
š End-to-End DevOps Project: Deploying Swiggy Clone with Terraform, Jenkins, SonarQube, Trivy & Docker
š Overview
In this production-ready DevOps implementation guide, we build a complete automated CI/CD and DevSecOps pipeline from scratch. Starting from Infrastructure as Code (IaC) using Terraform on AWS, we set up and configure Jenkins, integrate SonarQube for continuous code quality analysis, enforce Quality Gates, run Trivy vulnerability scans on filesystem and container images, and automate containerized deployment of a Swiggy Clone web application šā.
š„ Project Video Walkthrough
Watch the complete, end-to-end video tutorial explaining every step of this project:
šŗ Watch Full Video: DevOps Real-time Project | Deployment of SWIGGY App (YouTube)
Author: Kastro Kiran V
šļø Architecture & Pipeline Flow
[ Git / GitHub ] āāāāŗ [ Jenkins CI Server ]
ā
āāāŗ 1. Clean Workspace & Git Checkout
āāāŗ 2. SonarQube Static Analysis & Quality Gate Check
āāāŗ 3. NPM Dependencies Installation
āāāŗ 4. Trivy Filesystem Vulnerability Scan
āāāŗ 5. Docker Image Build & Tagging
āāāŗ 6. Trivy Container Image Security Scan
āāāŗ 7. Push to DockerHub Registry
āāāŗ 8. Deploy Container (Docker Run on Port 3000) āāāŗ [ Live Users ]
š Prerequisites & Port Requirements
Ensure your AWS EC2 instance has appropriate resources (Recommended: t2.large or t3.large, 2ā4 vCPUs, 8 GB RAM, 30 GB EBS Storage) and the following inbound ports opened in your Security Group:
| Service | Port | Protocol | Purpose |
|---|---|---|---|
| SSH | 22 | TCP | Remote EC2 Administration |
| Jenkins | 8080 | TCP | Jenkins CI/CD Automation Web UI |
| SonarQube | 9000 | TCP | SonarQube Code Quality Dashboard |
| Swiggy App | 3000 | TCP | Live Deployed React/Node Application |
š ļø Step 1: Provision AWS Infrastructure with Terraform
We use Terraform to define our cloud infrastructure declaratively, ensuring repeatable and reproducible deployments.
š GitHub Repository for Terraform Code:
š Terraform-Script-Swiggy-sandeep
š Key Terraform Files:
main.tfā Terraform backend configuration, provider pinning, and core infrastructure setup.provider.tfā AWS provider definition, specifying target region and credentials.resource.tfā Provisions EC2 instance, VPC, Subnets, Security Groups, IAM Roles, and Key Pairs.variables.tf/outputs.tfā Dynamic input variables (AMI, instance types) and useful outputs (public IP address, DNS).
ā” Terraform Execution Commands:
# 1. Initialize provider plugins and backend
terraform init
# 2. Review execution plan and dry-run infrastructure diff
terraform plan
# 3. Provision EC2 instance, networking, and security groups
terraform apply -auto-approve
# (When finished with project) Teardown all cloud resources to avoid costs
# terraform destroy -auto-approve

š Your EC2 instance and networking stack are now provisioned and running!
š» Step 2: Connect to EC2 & Verify Services
You can connect directly from your browser using AWS EC2 Instance Connect:
- Navigate to AWS Management Console ā EC2 ā Instances.
- Select your provisioned instance.
- Click Connect ā EC2 Instance Connect ā Connect.

š Verify Running Services:
Once your setup script/userdata has finished running, access the web dashboards:
- Jenkins Web UI:
http://<EC2-PUBLIC-IP>:8080

- SonarQube Dashboard:
http://<EC2-PUBLIC-IP>:9000

š§ Step 3: Jenkins Plugins & Tool Configuration
š§© 1. Install Necessary Jenkins Plugins
Navigate to Manage Jenkins ā Plugins ā Available Plugins, search for and install:
- ā Eclipse Temurin installer (JDK): Provides Java runtimes required by Jenkins and the SonarQube Scanner.
- ā Pipeline Stage View: Visualizes pipeline stages cleanly in real-time.
- ā SonarQube Scanner: Enables static code analysis and transmits findings directly to the SonarQube dashboard.
- ā NodeJS: Allows Jenkins to manage and switch Node.js versions for front-end dependency builds.
- ā Docker (Common, Pipeline, API): Grants pipeline access to Docker commands for building, tagging, and pushing images.

āļø 2. Global Tool Configuration
Once plugins are installed, configure runtime versions under Manage Jenkins ā Tools (Global Tool Configuration):
- JDK Installation:
- Name:
jdk17 - Source: Install automatically from adoptium.net (Java 17 LTS).
- Name:
- SonarQube Scanner Installations:
- Name:
sonar-scanner - Version:
sonar-scanner (v6.2.1.4610)or latest stable.
- Name:
- NodeJS Installations:
- Name:
node20 - Version:
NodeJS 20.x(LTS).
- Name:
- Docker Installations:
- Name:
docker - Version: Latest Docker CLI.
- Name:

š¾ Click Apply and Save.
š Step 4: Integrate SonarQube with Jenkins
1. Generate SonarQube User Authentication Token
- Access SonarQube at
http://<EC2-IP>:9000(Default credentials:admin/admin). - Go to Administration ā Security ā Users.
- Under the Tokens column for
Administrator, click the token icon. - Name the token
sonar-tokenand click Generate. - Copy the generated token string.

2. Store SonarQube Token in Jenkins Credentials
- Go to Manage Jenkins ā Credentials ā System ā Global credentials ā Add Credentials.
- Kind:
Secret text - Secret: Paste the generated SonarQube token.
- ID:
sonar-token - Description:
SonarQube Authentication Token - Click Create.

3. Create Quality Gate Webhook in SonarQube
To allow SonarQube to notify Jenkins when Quality Gate checks pass or fail:
- In SonarQube, navigate to Administration ā Configuration ā Webhooks.
- Click Create.
- Name:
jenkins-webhook - URL:
http://<EC2-PUBLIC-IP>:8080/sonarqube-webhook/ - Click Create.

4. Configure SonarQube Server in Jenkins System Settings
- Go to Manage Jenkins ā System (Configure System).
- Scroll to the SonarQube servers section.
- Check Enable injection of SonarQube server configuration as environment variables.
- Click Add SonarQube:
- Name:
sonar-server(must match the name used in your Jenkinsfile) - Server URL:
http://<EC2-PUBLIC-IP>:9000 - Server authentication token: Select
sonar-tokenfrom the dropdown.
- Name:
- Click Save.

š³ Step 5: Configure DockerHub Credentials in Jenkins
To enable Jenkins to authenticate and push the built Docker image to DockerHub:
- Go to Manage Jenkins ā Credentials ā System ā Global credentials ā Add Credentials.
- Fill in the fields:
- Kind:
Username with password - Username: Your DockerHub username
- Password: Your DockerHub password or Personal Access Token
- ID:
docker-creds(referenced in pipeline script) - Description:
DockerHub Registry Credentials
- Kind:

- Click Create to save the credentials.

š” Tip: Ensure the
jenkinssystem user has permissions to interact with the Docker daemon on the EC2 host:sudo usermod -aG docker jenkins sudo systemctl restart jenkins
š Step 6: Create Jenkins Pipeline Job
š GitHub Repository for Application Code:
š DevOps-Project-Swiggy
- Go to Jenkins Dashboard ā New Item.
- Enter item name:
Swiggy-DevOps-Pipeline. - Select Pipeline and click OK.

- Scroll down to the Pipeline script definition block and paste the declarative
Jenkinsfile:
š Declarative Jenkinsfile:
pipeline {
agent any
tools {
jdk 'jdk17'
nodejs 'node20' // Node.js 20 LTS
}
environment {
SCANNER_HOME = tool 'sonar-scanner'
DOCKER_IMAGE = 'sandeepallakonda/swiggy'
DOCKER_TAG = 'latest'
}
stages {
stage('Clean Workspace') {
steps {
cleanWs()
}
}
stage('Checkout from Git') {
steps {
git branch: 'master',
url: 'https://github.com/NotHarshhaa/DevOps-Projects/tree/master/DevOps-Project-41/DevOps-Project-Swiggy'
}
}
stage('SonarQube Code Analysis') {
steps {
withSonarQubeEnv('sonar-server') {
sh """
$SCANNER_HOME/bin/sonar-scanner \
-Dsonar.projectKey=Swiggy \
-Dsonar.projectName=Swiggy \
-Dsonar.sources=.
"""
}
}
}
stage('Quality Gate') {
steps {
script {
timeout(time: 2, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
}
stage('Install Dependencies') {
steps {
sh "npm install"
}
}
stage('Trivy Filesystem Security Scan') {
steps {
sh "trivy fs . --exit-code 0 --severity HIGH,CRITICAL -f table -o trivy-fs-report.txt"
archiveArtifacts artifacts: 'trivy-fs-report.txt', allowEmptyArchive: true
}
}
stage('Docker Build & Push') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-creds', toolName: 'docker') {
sh """
docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} .
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
"""
}
}
}
}
stage('Trivy Image Vulnerability Scan') {
steps {
sh "trivy image ${DOCKER_IMAGE}:${DOCKER_TAG} --exit-code 0 --severity HIGH,CRITICAL -f table -o trivy-image-report.txt"
archiveArtifacts artifacts: 'trivy-image-report.txt', allowEmptyArchive: true
}
}
stage('Deploy to Container') {
steps {
sh """
docker rm -f swiggy || true
docker run -d --name swiggy -p 3000:3000 ${DOCKER_IMAGE}:${DOCKER_TAG}
"""
}
}
}
post {
always {
echo "Pipeline execution finished."
}
success {
echo "š Swiggy Application deployed successfully to production container!"
}
failure {
echo "ā Pipeline failed! Please review stage logs and security reports."
}
}
}
š Step 7: Build, Scan & Deploy
Click Build Now on the Jenkins pipeline page.
š Pipeline Stage Flow:
- Clean Workspace ā Prepares fresh workspace directory.
- Checkout from Git ā Clones source code from GitHub repository.
- SonarQube Analysis ā Performs SAST code scanning and transmits metric data.
- Quality Gate ā Verifies SonarQube Quality Gate threshold status.
- Install Dependencies ā Installs NPM packages via Node 20.
- Trivy FS Scan ā Audits repository source dependencies for HIGH/CRITICAL CVEs.
- Docker Build & Push ā Builds production container image and pushes to DockerHub.
- Trivy Image Scan ā Scans the compiled container image layers for known vulnerabilities.
- Deploy Container ā Launches container exposed on port 3000.

š Live Application Verification
Open your web browser and navigate to:
š http://<EC2-PUBLIC-IP>:3000

š The Swiggy Clone web application is now successfully running live in Docker!
šÆ Summary & Key DevOps Takeaways
By completing this project, you have implemented a real-world enterprise DevSecOps workflow:
- āļø Infrastructure as Code (IaC): Automated cloud resource provisioning with Terraform.
- š Continuous Integration (CI): Automated builds, linting, and dependency tracking with Jenkins.
- š”ļø DevSecOps & Code Quality: SonarQube static code analysis + Quality Gate enforcement.
- š Vulnerability Management: Trivy multi-stage scanning on filesystems and container layers.
- š¦ Containerization & CD: Automated image packaging and production deployment with Docker.
š ļø Author & Community
This project is crafted by Harshhaa š”.
Iād love to hear your feedback! Feel free to share your thoughts.
š§ Connect with me:
š¢ Stay Connected

