This project demonstrates deploying a Flask app to Azure App Services and setting up CI/CD with Azure Pipelines.
- Azure account: Sign up for free
- Azure CLI installed: Azure CLI Installation Guide
Create and activate a virtual environment, then install Flask:
python3 -m venv ~/.flask-ml-azure
source ~/.flask-ml-azure/bin/activate
pip install flaskCreate a requirements.txt file:
flask
In the project root, create a file named app.py:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, Azure!"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)Run the app locally to test it:
python app.pyAccess the app at http://127.0.0.1:5000.
az loginUse the Azure CLI to create a resource group and deploy the Flask app:
az group create --name flask-rg --location eastus
az webapp up --name <your-app-name> --resource-group flask-rg --location eastus --sku B1- Replace
<your-app-name>with a unique name for your app. B1is the SKU for the Basic tier. Adjust it as needed.
Visit https://<your-app-name>.azurewebsites.net/ to confirm the app is live.
Initialize a Git repository:
git init
git add .
git commit -m "Initial commit"
git remote add origin <your-github-repo-url>
git push -u origin main- Go to Azure DevOps and create a new project.
- In Pipelines, create a new pipeline and connect it to your GitHub repository.
In your project, create a .github/workflows/azure-pipelines.yml file with the following:
git add .github/workflows/azure-pipelines.yml
git commit -m "Set up Azure Pipelines"
git pushAzure Pipelines will automatically run on each push, deploying any updates to your Azure App Services instance.
If you encounter a quota error for PremiumV2 instances, use one of the following options:
- Change SKU: Use a lower SKU (e.g.,
B1orS1) when running theaz webapp upcommand:az webapp up --name <your-app-name> --resource-group flask-rg --location eastus --sku B1
- Change Region: Choose a region with available PremiumV2 capacity (e.g.,
centralusorwestus):az webapp up --name <your-app-name> --resource-group flask-rg --location centralus --sku P1v2
- Request Quota Increase: Submit a request through the Azure Portal under Help + Support for a PremiumV2 quota increase in the desired region.
Test the deployed application by visiting https://<your-app-name>.azurewebsites.net/. Update any additional scripts for testing or prediction to point to the deployed URL.