I'm trying to deploy a FastAPI application (as Web app) to Azure App Service using GitHub Actions. The deployment seems to be successful, but when I try to access the app, I get the message:
Status Code: 404
Status Message: The Resource 'Microsoft.Web/sites/my-fastapi-webapp/slots/e6dnb2bkfndyfpdx' under resource group 'my-fastapi-rg' was not found.
I am not using any slots.
Steps I’ve taken so far:
Tried redeploying: The deployment always references the non-existent slot.
GitHub Actions Workflow: I’m using the following configuration to deploy to Azure:
- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v3
with:
app-name: 'my-fastapi-webapp'
slot-name: 'Production'
Removed slot reference from the workflow, but the issue persists.
My questions:
ERROR - Container tdocs_0_40751cc1 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
The error you're encountering occurs because of the incorrect startup command.
I got the same error after using the startup command that you provided.
I changed the startup command to below one because
The apt-get update
command gives the list of available packages, and apt-get install -y libmagic1
installs the libmagic1
library, which is required by python-magic
to function properly.
Navigate to Configuration section of your Azure Web app - > add the startup command
and hit save.
apt-get update && apt-get install -y libmagic1 && gunicorn --worker-class uvicorn.workers.UvicornWorker --timeout 600 --access-logfile '-' --error-logfile '-' main:app
This is my workflow file:
name: Build and deploy Python app to Azure Web App - fastapitestsample18
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python version
uses: actions/setup-python@v1
with:
python-version: '3.12'
- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt
- name: Zip artifact for deployment
run: zip release.zip ./* -r
- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v3
with:
name: python-app
path: |
release.zip
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: python-app
- name: Unzip artifact for deployment
run: unzip release.zip
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: 'fastapitestsample18'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_6BE585852CEC4BCEB75B1EBBC05169D3 }}
Successfully deployed the application via GitHub actions.
Output after deployment: