AUTOMATED DEPLOYMENT
OF PYTHON WEB
APPLICATION VIA JENKINS
PIPELINE ON AWS EC2
Project Repository: https://github.com/dnp176/FinancesTrackProject_Live.git
Dhruv Patel (@dnp176)
📌EC2 Instance Creation for Jenkins
Steps:
1. Login to AWS Console
2. Go to EC2 → Launch Instance
Settings:
• Name: Jenkins_Machine
• AMI: Amazon Linux 2
• Instance Type: t2.micro
• Storage: 10 GB
• Key Pair: Select/Create
Security Group:
• Create new Security Group
• Allow following ports:
o 22 (SSH)
o 8080 (Jenkins)
o 5001 (Application)
Launch Instance:
• Click Launch
• Connect via SSH: ssh -i "key.pem" ec2-user@your-ip
DHRUV PATEL (@DNP176) 1
📌 Install Java 17 on EC2
sudo apt update
sudo apt install openjdk-17-jdk -y
java -version
📌 Install Jenkins on EC2
sudo apt update
sudo apt install openjdk-17-jdk -y
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key |
sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
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
sudo apt update
sudo apt install jenkins -y
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status Jenkins
Access Jenkins:
1. Open browser:
http://your-server-ip:8080
2. Get Jenkins initial password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
DHRUV PATEL (@DNP176) 2
📌 Install Pipeline: Stage View Plugin in Jenkins
Steps:
1. Open Jenkins Dashboard
2. Click Manage Jenkins
3. Click Manage Plugins
4. Go to Available tab
5. Search for Pipeline: Stage View
6. Check the checkbox
7. Click Install without restart
DHRUV PATEL (@DNP176) 3
📌 Install Docker on EC2
sudo apt update
sudo apt install ca-certificates curl gnupg -y
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --
dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-
by=/etc/apt/keyrings/docker.gpg]
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee
/etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-
plugin docker-compose-plugin -y
sudo systemctl start docker
sudo systemctl enable docker
sudo docker --version
sudo usermod -aG docker $USER
sudo usermod -aG docker jenkins
sudo systemctl restart docker
sudo systemctl restart Jenkins
DHRUV PATEL (@DNP176) 4
📌 Jenkins Pipeline Project Creation
1. Open Jenkins Dashboard.
2. Click on New Item (top-left corner).
3. Enter a name for your pipeline project (e.g., Fintrack_Pipeline).
4. Select Pipeline as the project type.
5. Click OK.
6. Scroll down to the Pipeline section.
7. In the Definition dropdown, select Pipeline script.
8. Paste the Jenkins Pipeline Script (given above) into the script textbox.
9. Click Save.
DHRUV PATEL (@DNP176) 5
📌 Jenkins Pipeline Script
pipeline {
agent any
environment {
APP_NAME = "fintrack_app"
CONTAINER_NAME = "${APP_NAME}_container"
APP_PORT = "5001"
IMAGE_TAG = "${env.BUILD_NUMBER}"
}
stages {
stage('Clean Workspace') {
steps {
cleanWs()
}
}
stage('Clone Code') {
steps {
git branch: 'main', url:
'https://github.com/dnp176/FinancesTrackProject_Live.git'
}
}
stage('Build Docker Image') {
steps {
script {
sh "docker build --no-cache -t
${APP_NAME}:${IMAGE_TAG} ."
}
}
}
stage('Stop & Remove Existing Container') {
steps {
script {
sh """
docker stop ${CONTAINER_NAME} || true
docker rm ${CONTAINER_NAME} || true
"""
}
}
}
DHRUV PATEL (@DNP176) 6
stage('Run Docker Container') {
steps {
script {
sh "docker run -p ${APP_PORT}:${APP_PORT} --name
${CONTAINER_NAME} -d ${APP_NAME}:${IMAGE_TAG}"
}
}
}
}
post {
always {
echo "Pipeline for ${APP_NAME} finished. Container:
${CONTAINER_NAME}, Image Tag: ${IMAGE_TAG}"
}
}
}
DHRUV PATEL (@DNP176) 7
📌 Application Access
Once the Docker container is running, open your browser and access your app at:
http://<EC2-Public-IP>:5001
DHRUV PATEL (@DNP176) 8
***
DHRUV PATEL (@DNP176) 9