0
0
Flaskframework~30 mins

CI/CD pipeline for Flask - Mini Project: Build & Apply

Choose your learning style9 modes available
CI/CD Pipeline for Flask Application
📖 Scenario: You have created a simple Flask web application. Now, you want to automate testing and deployment using a CI/CD pipeline. This project will guide you through setting up the basic files and configuration to enable continuous integration and continuous deployment for your Flask app.
🎯 Goal: Build a basic CI/CD pipeline configuration for a Flask app that installs dependencies, runs tests, and deploys the app automatically.
📋 What You'll Learn
Create a simple Flask app file named app.py with a basic route.
Add a requirements file named requirements.txt listing Flask.
Create a GitHub Actions workflow file named ci-cd.yml to automate install, test, and deploy steps.
Print the deployment success message at the end.
💡 Why This Matters
🌍 Real World
Automating testing and deployment saves time and reduces errors when updating web applications.
💼 Career
CI/CD pipelines are essential skills for DevOps engineers and developers to deliver software reliably and quickly.
Progress0 / 4 steps
1
Create a simple Flask app
Create a file named app.py with a Flask app that has one route / returning the text "Hello, CI/CD!". Use the variable name app for the Flask instance.
Flask
Need a hint?

Import Flask, create app = Flask(__name__), define a route / with a function returning the string.

2
Add requirements file
Create a file named requirements.txt containing the exact line Flask==2.3.2 to specify the Flask version dependency.
Flask
Need a hint?

Write Flask==2.3.2 exactly in requirements.txt to specify the Flask version.

3
Create GitHub Actions workflow
Create a file named .github/workflows/ci-cd.yml with a GitHub Actions workflow that triggers on push to main. The workflow should have a job named build that runs on ubuntu-latest. It should have steps to: checkout code, set up Python 3.12, install dependencies from requirements.txt, run tests by executing python -m unittest discover, and print Deployment successful! at the end.
Flask
Need a hint?

Use GitHub Actions syntax to define a workflow triggered on push to main. Include steps for checkout, Python setup, install, test, and a final echo message.

4
Print deployment success message
Add a print statement in app.py after the Flask app runs to print "Deployment successful!" to the console.
Flask
Need a hint?

Use print("Deployment successful!") after app.run() in app.py.