0% found this document useful (0 votes)
19 views4 pages

Kalim

Uploaded by

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

Kalim

Uploaded by

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

Automating Deployment of a Dockerized Web

Application using Jenkins CI/CD Pipeline on AWS


EC2

Student Name: Kalim Hussain

Registration Number: 2010-KIU-BS2010

Department of Computer Science, Faculty of Natural


Science and Engineering, KIU, Gilgit
September, 2024

Objective:

To create an automated CI/CD pipeline using Jenkins for deploying a Dockerized web
application on an AWS EC2 instance.

Step 1: Download a Website Template

1. Download a simple HTML/CSS website template from the internet.


2. Extract the downloaded website files to your local machine.
3. Review the files and ensure it has a index.html page for testing.

Step 2: Push the Website to a GitHub Repository

 Initialize a Git repository in the website folder git init


 Add the files and commit the changes (git add . 2.git commit -m "Initial
commit of website files”)
 Create a new repository on GitHub and copy the repository URL.
 Add the GitHub remote to your local repository: git remote add origin
https://github.com/kalim-hussain/FinalWeb
 Push the code to the GitHub repository: git push -u origin main

Step 3: Set Up an EC2 Instance on AWS

1. Launch an EC2 instance using the AWS Management Console.


2. Choose an Ubuntu image (Amazon Machine Image - AMI) and instance type
(e.g., t2.micro).
3. Configure security groups to allow:
 SSH access on port 22.
 HTTP access on port 80 for web traffic.
 Port 8080 if needed for Jenkins.
4. Launch the instance and connect to it using SSH
Step 4: Install Docker on EC2

1. Update the packages: sudo apt-get update


2. Install Docker: sudo apt-get install docker.io
3. Add the current user to the Docker group to run Docker without sudo
usermod -aG docker ubantu

Step 5: Create a Dockerfile for the Website

1. Create a Dockerfile in the website's root directory


FROM nginx:alpine
COPY . /usr/share/nginx/html
EXPOSE 80
2. The Dockerfile uses the nginx image and copies the website files into the
default nginx directory.

Step 6: Build and Tag the Docker Image

1. Build the Docker image using the Dockerfile:


docker build -t hussainkalim43/website-image .
2. Tag the Docker image with your Docker Hub repository
docker tag website-image <hussainkalim43>/website-image

Step 7: Push the Docker Image to Docker Hub

1. Log in to Docker Hub: docker login


2. Push the image to Docker Hub: docker push wehussainkalim43/website-
image

Step 8: Install Jenkins on EC2

1. Install Java
sudo apt-get install openjdk-17-jdk
2. Add the Jenkins repository and install Jenkins
#wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key
#add - sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ >
/etc/apt/sources.list.d/jenkins.list'
#sudo apt-get update
#sudo apt-get install Jenkins
3. Start Jenkins and open the web interface
sudo systemctl start Jenkins
4. Access Jenkins at http://<your-ec2-ip>:8080 and complete the initial setup by
unlocking it.

Step 9: Set Up a Jenkins Pipeline

1. Create a new Jenkins pipeline job.


2. Configure the pipe line

Step 10: Configure Jenkins to Use GitHub

1. Go to the GitHub repository and create a webhook pointing to http://<your-


ec2-ip>:8080/github-webhook/.
2. Add your GitHub repository URL to the Jenkins job under "Source Code
Management.

Step 11: Test the Jenkins Pipeline

1. Push changes to your GitHub repository to trigger the pipeline automatically.


2. Jenkins will pull the latest code, build the Docker image, and deploy the
updated website to the Docker container.

Step 12: Verify the Deployment

1. Open a browser and navigate to http://<your-ec2-ip>.


2. Verify that the website is running and the changes are reflected.

You might also like