L2 - 7 - Daily Task - 7
L2 - 7 - Daily Task - 7
Batch No.:WLBatchB029
L2_7_DAILY TASK - 7
First, make sure Python is installed on your system. Then, install Flask:
mkdir flask-jenkins-docker
cd flask-jenkins-docker
flask-jenkins-docker/
│── app.py
│── templates/
│ └── index.html
│── requirements.txt
│── Dockerfile
│── Jenkinsfile
app = Flask(__name__)
@app.route("/")
def home():
return render_template("index.html")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)
• This script starts a Flask web server and serves the index.html file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flask Web App</title>
</head>
<body>
<h1>Welcome to My Flask Web App – Kunal Pradeep Purih1>
</body>
</html>
1.5 Define Dependencies in requirements.txt
flask
git init
git add .
git commit -m "Initial commit"
pipeline {
agent any
environment {
DOCKER_IMAGE = "flask-app"
CONTAINER_NAME = "flask-container"
}
stages {
stage('Checkout Code') {
steps {
git branch: 'main', url:
'https://github.com/yourusername/flask-jenkins-docker.git'
}
}
stage('Clean Up') {
steps {
script {
sh 'docker system prune -f'
}
}
}
}
}
Run:
docker ps
http://localhost:5000