Project 1: Jenkins CI/CD Pipeline with GitHub Webhook Integration for Docker Application Deployment on AWS EC2


Welcome back, DevOps Enthusiasts! After a productive break, I'm thrilled to resume my 60 Days DevOps Challenge and this Day 59 with Project 1, where we implement a CI/CD pipeline using Jenkins, Docker, and GitHub webhooks to deploy a web application on AWS EC2 instances. This hands-on project demonstrates a powerful automation workflow that mirrors real-world deployment pipelines.
Objective
To build and automate a deployment pipeline that:
Pulls code from a GitHub repository
Builds a Docker image
Runs the image as a container on an EC2 instance
Triggers automatically via GitHub webhook on every push
Step-by-Step Implementation
1. Launch Your Jenkins EC2 Instance
Instance Name:
project-1
AMI: Ubuntu
Instance Type:
t2.micro
Authentication: Key pair login (
project_key.pem
)Security Groups: Allow HTTP, HTTPS, SSH (port 22), Jenkins (port 8080), and App (port 8001)
Launc the instance and wait until your instance ready
Click on Connect
Copy the
2. SSH into Your EC2
Open CMD/Terminal in your PC
Navigate to your project_key.pem
file location and run: (e.g.- C:\Users\Nitin Dhiman\Downloads)
Copy this code to your terminal
chmod 400 docker.pem #To make this file executable
ssh -i "docker.pem" ubuntu@<your-public-ip>
4. Install Jenkins
Follow the official Jenkins installation guide. This will also install Java.
To install Jenkins, first we need to install Java in ubuntu EC2 instance
Installation of Java
Jenkins requires Java to run, yet not all Linux distributions include Java by default. Additionally, not all Java versions are compatible with Jenkins.
There are multiple Java implementations which you can use. OpenJDK is the most popular one at the moment, we will use it in this guide.
Update the Debian apt repositories, install OpenJDK 21, and check the installation with the commands:
sudo apt update
sudo apt install fontconfig openjdk-21-jre
java -version
Output:
Openjdk version "21.0.3" 2024-04-16
OpenJDK Runtime Environment (build 21.0.3+11-Debian-2)
OpenJDK 64-Bit Server VM (build 21.0.3+11-Debian-2, mixed mode, sharing)
Jenkins Weekly release
A new release is produced weekly to deliver bug fixes and features to users and plugin developers. It can be installed from the debian
apt repository.
sudo wget -O /etc/apt/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian/jenkins.io-2023.key
echo "deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
5. Install Docker
sudo apt update
sudo apt install docker.io -y
Verify installations:
jenkins --version
docker --version
Add Docker to the user group for both jenkins and the local user.
sudo usermod -aG docker jenkins
sudo usermod -aG docker $USER
#reboot your instance
sudo reboot
6. Open Jenkins in Browser
Add inbound rules for ports 8080
and 8001
. Then access Jenkins via:
http://<public-ip>:8080
Unlock Jenkins:
cat /var/lib/jenkins/secrets/initialAdminPassword
Install Suggested Plugins
Create First Admin User (with your credentials) & Save and Continue
CI/CD Pipeline Setup
7. Create Jenkins Project
Go to Jenkins Dashboard > New Item
Name:
react_django_demo_app
Type: Freestyle Project
8. Configure GitHub Integration
Source Code Management: Git
Add your GitHub repository URL
Add your Git repo’s branch name to build
9. Add Build Script (Execute Shell)
10. Trigger Your First Build
Click on Build Now
View logs via Console Output
Visit:
http://<public-ip>:8001
GitHub Webhook Automation
11. Configure Build Triggers
Build Trigger: GitHub hook trigger for GitScm polling
12. Add Webhook to GitHub Repo
GitHub Repo > Settings > Webhooks > Add Webhook
Payload URL:
http://<public-ip>:8080/github-webhook/
(http://3.110.167.104:8080/github-webhook/)Content Type: application/json
Trigger Event: Just the push event
Final Outcome
Now, every time you push code to your GitHub repo:
Jenkins pipeline is triggered automatically
Docker image is rebuilt
Updated container is deployed on EC2
Your application reflects the latest code changes instantly
Key Takeaways
GitHub + Jenkins + Docker creates a powerful CI/CD flow
Webhook automation eliminates manual deployment steps
Running on EC2 ensures real-world deployment simulation
Subscribe to my newsletter
Read articles from Nitin Dhiman directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
