Skip to main content

Command Palette

Search for a command to run...

🚀 Flask Web App with Automated CI/CD Pipeline

Updated
2 min read

on AWS EC2In this project, I built and deployed a Flask web application with a fully automated CI/CD pipeline Here’s a step-by-step demo plan for your project “Flask Web App with Automated CI/CD Pipeline on AWS EC2” using Docker + Jenkins + AWS EC2.


🔹 Demo Flow (What you’ll show)

  1. Flask App → Simple "Hello from Flask!" web app.

  2. Dockerize App → Build Docker image for Flask app.

  3. Push to GitHub → Store code & Dockerfile.

  4. Jenkins Pipeline → Automates build & deployment.

    • Triggered on GitHub push.

    • Builds Docker image.

    • Runs container on EC2.

  5. Access Web App → Public URL of EC2 showing Flask app running.


🔹 Step-by-Step Setup

1️⃣ Flask App

Create app.py:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return "🚀 Hello from Flask CI/CD on AWS EC2!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)

2️⃣ Dockerfile

FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]

requirements.txt:

flask

3️⃣ Launch AWS EC2

  • OS: Ubuntu 22.04

  • Open Security Group: 5000, 8080, 22

Install tools:

sudo apt update -y
sudo apt install docker.io git -y

4️⃣ Install Jenkins

sudo apt install openjdk-11-jdk -y
wget -q -O - https://pkg.jenkins.io/debian-stable/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 update -y
sudo apt install jenkins -y

Start Jenkins:

sudo systemctl enable jenkins
sudo systemctl start jenkins

Access → http://<EC2-IP>:8080


5️⃣ Jenkins Pipeline

In Jenkins, create a Pipeline Job → GitHub repo → Add Jenkinsfile.

Jenkinsfile

pipeline {
    agent any
    stages {
        stage('Clone Repo') {
            steps {
                git 'https://github.com/<your-username>/<repo>.git'
            }
        }
        stage('Build Docker Image') {
            steps {
                sh 'docker build -t flask-ci-cd-app .'
            }
        }
        stage('Run Docker Container') {
            steps {
                sh '''
                docker rm -f flask-app || true
                docker run -d --name flask-app -p 5000:5000 flask-ci-cd-app
                '''
            }
        }
    }
}

6️⃣ Final Test

  • Commit & push code → GitHub.

  • Jenkins auto-builds & deploys container on EC2.

  • Open in browser → http://<EC2-IP>:5000Flask app live! 🎉


👉 This demo shows:
✅ Flask App
✅ Dockerization
✅ CI/CD with Jenkins
✅ Deployment on AWS EC2

More from this blog

Amazon S3 Storage Classes

43 posts