Preface
I have a FastAPI app. The most important part for that is: In app.main
there exists the object app
which is the app that should run. I want to deploy that to an Azure App Service.
Azure Preparation
- In Azure, select App Services and create a new app.
- Choose a subscription and a resource group.
- Web app name should obviously be unique; at least this will be used as the endpoint.
- As region I chose West Europe.
- Linux plan - I just created a new one.
- Pricing plan - I chose “Free F1” as this is just for testing.
- Keep the rest as is and directly go to “Review + Create”.
- Check everything and click “Create” again.
App Configuration
- Every configuration my application reads from the command line should be set in the app in “Configuration”, as “Application Setting”.
- Add another configuration:
SCM_DO_BUILD_DURING_DEPLOYMENT
with valuetrue
. We will (for now) do manual deployment via command line, hence this is required. - Configure the path to execute: In the configuration settings, go to “General settings” and update the startup command as follows:
Not quite sure yet why we are using gunicorn here…gunicorn -w 4 -k uvicorn.workers.UvicornWorker app.main:app
App deployment
Next steps are mostly done from your local command line.
- Generate a zip file
out.zip
with all the required files:app/*.py
requirements.txt
- Push your files to Azure:
az webapp deploy --resource-group ${your_resource_group} --name ${your_app_name} --src-path out.zip
Success!
Now the webapp should be available via https://${your_app_name}.azurewebsites.net
.