ProDevOpsGuy
All Guides
#DevOps#CI/CD#Terraform#Jenkins

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.

•9 min read
•By NotHarshhaa

šŸš€ 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:

DevOps Real-time Project | Deployment of SWIGGY App

šŸ“ŗ 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:

ServicePortProtocolPurpose
SSH22TCPRemote EC2 Administration
Jenkins8080TCPJenkins CI/CD Automation Web UI
SonarQube9000TCPSonarQube Code Quality Dashboard
Swiggy App3000TCPLive 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

Terraform Infrastructure Architecture

šŸŽ‰ 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:

  1. Navigate to AWS Management Console → EC2 → Instances.
  2. Select your provisioned instance.
  3. Click Connect → EC2 Instance Connect → Connect.

AWS EC2 Instance Connect

šŸ”— Verify Running Services:

Once your setup script/userdata has finished running, access the web dashboards:

  • Jenkins Web UI:
    http://<EC2-PUBLIC-IP>:8080

Jenkins Service Dashboard

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

SonarQube Service Dashboard


šŸ”§ 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.

Jenkins Available Plugins Setup


āš™ļø 2. Global Tool Configuration

Once plugins are installed, configure runtime versions under Manage Jenkins → Tools (Global Tool Configuration):

  1. JDK Installation:
    • Name: jdk17
    • Source: Install automatically from adoptium.net (Java 17 LTS).
  2. SonarQube Scanner Installations:
    • Name: sonar-scanner
    • Version: sonar-scanner (v6.2.1.4610) or latest stable.
  3. NodeJS Installations:
    • Name: node20
    • Version: NodeJS 20.x (LTS).
  4. Docker Installations:
    • Name: docker
    • Version: Latest Docker CLI.

Jenkins Global Tool Configuration

šŸ’¾ Click Apply and Save.


šŸ” Step 4: Integrate SonarQube with Jenkins

1. Generate SonarQube User Authentication Token

  1. Access SonarQube at http://<EC2-IP>:9000 (Default credentials: admin / admin).
  2. Go to Administration → Security → Users.
  3. Under the Tokens column for Administrator, click the token icon.
  4. Name the token sonar-token and click Generate.
  5. Copy the generated token string.

Generate SonarQube User Token


2. Store SonarQube Token in Jenkins Credentials

  1. Go to Manage Jenkins → Credentials → System → Global credentials → Add Credentials.
  2. Kind: Secret text
  3. Secret: Paste the generated SonarQube token.
  4. ID: sonar-token
  5. Description: SonarQube Authentication Token
  6. Click Create.

Add SonarQube Token to Jenkins Credentials


3. Create Quality Gate Webhook in SonarQube

To allow SonarQube to notify Jenkins when Quality Gate checks pass or fail:

  1. In SonarQube, navigate to Administration → Configuration → Webhooks.
  2. Click Create.
  3. Name: jenkins-webhook
  4. URL: http://<EC2-PUBLIC-IP>:8080/sonarqube-webhook/
  5. Click Create.

Configure Webhook in SonarQube


4. Configure SonarQube Server in Jenkins System Settings

  1. Go to Manage Jenkins → System (Configure System).
  2. Scroll to the SonarQube servers section.
  3. Check Enable injection of SonarQube server configuration as environment variables.
  4. 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-token from the dropdown.
  5. Click Save.

Configure SonarQube Server in Jenkins System Settings


🐳 Step 5: Configure DockerHub Credentials in Jenkins

To enable Jenkins to authenticate and push the built Docker image to DockerHub:

  1. Go to Manage Jenkins → Credentials → System → Global credentials → Add Credentials.
  2. 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

Add DockerHub Credentials in Jenkins

  1. Click Create to save the credentials.

DockerHub Global Credentials Saved

šŸ’” Tip: Ensure the jenkins system 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

  1. Go to Jenkins Dashboard → New Item.
  2. Enter item name: Swiggy-DevOps-Pipeline.
  3. Select Pipeline and click OK.

Create Jenkins Pipeline Project

  1. 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:

  1. Clean Workspace → Prepares fresh workspace directory.
  2. Checkout from Git → Clones source code from GitHub repository.
  3. SonarQube Analysis → Performs SAST code scanning and transmits metric data.
  4. Quality Gate → Verifies SonarQube Quality Gate threshold status.
  5. Install Dependencies → Installs NPM packages via Node 20.
  6. Trivy FS Scan → Audits repository source dependencies for HIGH/CRITICAL CVEs.
  7. Docker Build & Push → Builds production container image and pushes to DockerHub.
  8. Trivy Image Scan → Scans the compiled container image layers for known vulnerabilities.
  9. Deploy Container → Launches container exposed on port 3000.

Jenkins Pipeline Stages Execution View


🌐 Live Application Verification

Open your web browser and navigate to:

šŸ‘‰ http://<EC2-PUBLIC-IP>:3000

Swiggy App Live Deployed

šŸ” 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:

LinkedIn GitHub Telegram Dev.to Hashnode


šŸ“¢ Stay Connected

Follow Me

Categorized Under
DevOpsCI/CDTerraformJenkinsSonarQubeTrivyDockerAWS