Deploy Flask app on Azure in 3 steps

Omar Rady
5 min readMay 18, 2022

Deploy Flask app on Azure in 3 steps! Based on my recent experience, I’ll demonstrate how to deploy and publish your Flask web app on Azure App service.
Azure App Service offers scalable web hosting services that run on the Linux operating system.

The majority of online tutorials demonstrate how to deploy a rather simple flask app (concept demo), ignoring the fact most flask apps have a file hierarchy.
In this blog, I intended to walk you through the process of deploying a Flask application with a standard structure, such as a few pages/routes and directories. Please keep in mind that this blog is not about Flask as a framework or coding in general.

Step 1: Configure your app

The flask app structure shown above is the one I’ve successfully deployed; yours does not have to be the same, though it may look very similar as this is the Flask web app standard architecture.
We are mostly concerned with three files when it comes to Azure deployment configuration:

  • requirements.txt
  • setup.py
  • app.py

requirements.txt

The requirements.txt file should list all Python libraries on which your application is dependent. A file with this name added to the project root is automatically detected and installed by Python Integrated tools. Azure App Service includes a Python stack (2, 3); ensure that your required packages are compatible with the Python stack you choose.

setup.py

Instruct the system environment to create symlinks to the source directory within site-packages. It informs setup tools about your package (such as the name and version) and which code files to include.

In this case, the “application” folder is where we include code files, so we include its name in the setup.

app.py

By default, Azure app service will search for an app.py or application.py file as the web app’s starting point. If you name it differently, you’ll need to configure the Azure portal startup command.

Step 2: Create Azure Web App Resource

Sign into the Azure portal using your account.

  • On the Azure portal menu or from the Home page, select Create a resource. Everything you create on Azure is a resource.
  • The portal navigates you to the Marketplace page. From here, you can search for the resource you want to create or select one of the popular resources that people create in the Azure portal.
  • Select Web > Web App to display the web app creation wizard.
  • Fill out the wizard with the correct python version of your app and operating system is Linux

It should resemble the illustration below:

Select Review and Create to navigate to the review page, then select Create to create the app.
It may take a few seconds for your web app to be created and ready for use. The portal will display the deployment page, where you can view the status of your deployment. Once the app is ready, navigate to the new app in the Azure portal:

  • On the Azure portal menu or from the Home page, select All resources.
  • Select the App Service for your web app from the list. Make sure to select the App Service and not the App Service Plan.
  • To preview your new web app’s default content, select its URL at the top right. The placeholder page that loads indicates that your web app is up and running and ready to receive deployment of your app’s code.

Step 3: Build and Deploy your app

There are three primary stages in the development and deployment of any app pipeline.

  • Repository of source code
  • Build technology
  • Deployment method

In this demonstration, I will use the local machine’s git repository as the source code repository and the Kudu build server as the building technology. Navigate to Deployment center and choose Local git from the options menu.

Select Kudu as the build server

Navigate to Deployment credentials where you’ll find the git clone URI along with git remote connection credentials
https://your-app-name.scm.azurewebsites.net/your-app-name.git

Open a git terminal in your local repository and push your app to the remote location you obtained in the previous step.

git remote add azure-hello https://your-app-name.scm.azurewebsites.net:443/your-app-name.git git commit -a -m “first commit” git push azure-hello master

When prompted for credentials by Git Credential Manager, enter the credentials that you created in the Deployment step on Azure portal.

If the name of your start entry file is not “app.py” or “application.py,” you must modify the start entry file command in Application settings.

gunicorn — bind=0.0.0.0 — timeout 600 yourstartupfilename:app

Done!

We successfully deployed your Flask app to Azure web app services.

Please feel free to drop your question in the comments section.

--

--

Omar Rady

Engineer interested in Tech / Travelling / Economy