0% found this document useful (0 votes)
23 views35 pages

Jenkins - 1

Uploaded by

manikandanacecse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views35 pages

Jenkins - 1

Uploaded by

manikandanacecse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

KAVIT DEEPAK MEHTA

Amazon Clone Website Integrated with


CI/CD Pipeline using Jenkins and GitHub
Aim:
The aim of this project is to build an Amazon clone website integrated into a Continuous
Integration and Continuous Deployment (CI/CD) pipeline using Jenkins. The pipeline
automates code building, testing, and deployment to an NGINX server hosted on an AWS
EC2 instance. This project highlights how DevOps practices streamline web development
and deployment processes.

Components:
Amazon Clone Website: A fully functional web application mimicking the functionality of
Amazon's e-commerce platform.
CI/CD Pipeline:

o GitHub: Source code repository and version control system.


o Jenkins: Automation server that orchestrates building, testing, and deploying the code.
o GitHub Webhook: Triggers Jenkins to initiate the build process when code is pushed or
updated.

AWS EC2 Instance: Hosts the NGINX web server and runs the deployed Amazon clone
website.
NGINX: Web server responsible for serving the Amazon clone website.
GitHub Token: Credentials used to securely integrate GitHub with Jenkins for automated
builds.

Architecture:
KAVIT DEEPAK MEHTA

Problem Definiton:
Developing and deploying web applications can be time-consuming and error-prone
without automation. Manual deployment processes often lead to inconsistencies, delays,
and configuration issues. This project solves these challenges by automating the entire
process, from code push to deployment, using Jenkins and a CI/CD pipeline. This ensures
faster, more reliable, and repeatable deployments.

Steps:

1. Create an EC2 Instance

● Instance Name: Amazon Clone


● AMI: Ubuntu 24.04
● Instance Type: t2.micro
● Security Group: Enable
o HTTP
o HTTPS
o Custom TCP (8080, Anywhere)
o Custom TCP (8000, Anywhere)
● Action: Launch the instance.
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA

2. Connect to the EC2 Instance and Install Required Packages


Run the following commands in the terminal after connecting via SSH:
# Update the package list

sudo apt update

# Install OpenJDK 17

sudo apt install openjdk-17-jdk

# Verify the Java installation

java -version

# Add the Jenkins GPG key

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-


stable/jenkins.io-2023.key

# Add Jenkins repository to the sources list

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


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

# Update the package list

sudo apt-get update

# Install Jenkins

sudo apt-get install jenkins

# Enable Jenkins to start on boot and start the service

sudo systemctl enable jenkins

sudo systemctl start jenkins

# Check Jenkins status

sudo systemctl status jenkins

# Install and start Nginx

sudo apt install nginx -y

sudo service nginx start

# Enable Nginx to start on boot

sudo service nginx enable

# Check Nginx status

sudo service nginx status


KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA

3. Access Jenkins

● Copy the Public IP Address of the EC2 instance and paste it into a browser followed
by :8080.
o Example: http://43.205.241.55:8080
● Use the initialAdminPassword located in
/var/lib/jenkins/secrets/initialAdminPassword.
● Follow the Jenkins setup steps:
o Click Install Suggested Plugins.
o Create a username, password, and provide email details.
KAVIT DEEPAK MEHTA

o Click Save & Continue and Start Using Jenkins.


KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA

4. Create GitHub Personal Access Token

● Go to GitHub Profile → Settings → Developer Settings → Personal Access Tokens


(classic).
● Generate a new token:
o Note: Jenkins-CICD
o Expiration: 30 days
o Scopes: Enable repo and workflow.
● Copy the Personal Access Token.
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA

5. Connect Jenkins to GitHub

● In Jenkins:
o Navigate to Manage Jenkins → Configure System.
o Scroll down to GitHub Server:
▪ Name: GitHub
▪ API URL: https://api.github.com
▪ Credentials: Add the Personal Access Token.
▪ Kind: Secret Text
▪ Secret: (Paste the personal access token).
▪ ID: Jenkins-For-CICD.
KAVIT DEEPAK MEHTA

o Test the connection to see your GitHub username and Save.

Scroll Down
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA

6. Create a Jenkins Job

● In Jenkins, create a new item:


o Item Name: kdm-amazon-clone
o Type: Freestyle Project
o General: Enable GitHub Project and provide the repository URL.
o Source Code Management:
KAVIT DEEPAK MEHTA

▪ Repository URL: https://github.com/KavitDeepakMehta/AMAZON-


CLONE
▪ Branch Specifier: */main
o Build Steps:
▪ Add build step: Execute Shell and enter the following commands:

▪ sudo docker ps --filter "publish=8000" -q | xargs -r docker rm -f


▪ sudo docker build . -t kdm-amazon-clone
▪ sudo docker run -p 8000:80 -d kdm-amazon-clone
o Save and click Build Now. After success, access the web app via
http://43.205.241.55:8000.

Copy Github repo URL

Go Back To Jenkins:
KAVIT DEEPAK MEHTA

Paste URL over here


KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA

Before Clicking Build Now, Go to EC2 and do this:

Add in last line and save


KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA

7. Automate Deployment Using SSH Keys and Webhooks

● Generate SSH keys:

⮚ # Generate SSH keys


⮚ ssh-keygen
⮚ # Navigate to the .ssh directory
⮚ cd .ssh
⮚ # List all files
⮚ ls -al
⮚ # View public SSH key
⮚ cat ~/.ssh/id_ed25519.pub
⮚ # View private SSH key (use cautiously)
⮚ cat ~/.ssh/id_ed25519
KAVIT DEEPAK MEHTA

Copy the public key and add it to GitHub:

● Settings → SSH and GPG Keys → New SSH Key.


KAVIT DEEPAK MEHTA

● Title: Jenkins Public SSH Key.


● Key Type: Authentication Key.
● Key: (Paste the public key).

In Jenkins, add the private SSH key:

● Manage Jenkins → Configure System → GitHub Server:


o Kind: SSH Username and Private Key.
o Private Key: Enter the private SSH key manually.
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA

8. Set Up GitHub Webhooks

● In GitHub:
o Go to Repository Settings → Webhooks → Add Webhook.
o Payload URL: http://43.205.241.55:8080/github-webhook/
o Content Type: application/json.
o Add the webhook.
● In Jenkins:
o Go to the kdm-amazon-clone Job.
o Under Build Triggers, enable GitHub hook trigger for GITScm polling.
KAVIT DEEPAK MEHTA
KAVIT DEEPAK MEHTA

9. Grant Docker Permissions to Jenkins

● Run the following commands to grant Jenkins permission to run Docker:

⮚ # Add Jenkins user to the Docker group


⮚ sudo usermod -aG docker jenkins
⮚ # Restart Jenkins and Docker
⮚ sudo systemctl restart jenkins
⮚ sudo systemctl restart docker
⮚ # Verify group membership
⮚ sudo su - jenkins
⮚ groups
⮚ # Should see "jenkins docker"
⮚ exit

10. Test Automatic Builds

● Make a change in the GitHub Repository (e.g., modify index.html) and commit it.
KAVIT DEEPAK MEHTA

● Jenkins will automatically trigger the build process, and the web application should
reflect the changes in real-time.
KAVIT DEEPAK MEHTA

BEFORE:

AFTER:

Expected Outcome:
The expected outcome is an Amazon clone website hosted on an NGINX server running on
an AWS EC2 instance. The CI/CD pipeline will be configured to automatically build, test,
KAVIT DEEPAK MEHTA

and deploy new code to the EC2 instance upon any changes in the GitHub repository,
ensuring an efficient, automated deployment process.

You might also like