I am trying to deploy my fastapi code on azure webapp. I want to write the startup command in the webapp configuration to run the fastapi. Ideally this command should be python -m uvicorn app:app --host 0.0.0.0 but since my app.py file is not the root folder but in another folder named 'test', I tried writing the command as: python -m uvicorn --chdir test app:app --host 0.0.0.0 and python -m uvicorn test.app:app --host 0.0.0.0 and python -m uvicorn test/app:app --host 0.0.0.0 but none of them is working. What should I do? Am I doing something wrong? I get an 'application error' on the webapp when I put any of these commands in the starup.error

I also tried writing python -m uvicorn app:app --host 0.0.0.0 in a startup.sh file and added it to the startup command field in azure webapp but that also does not work.startup command

I think the problem is it is unable to detect uvicorn. But I am installing uvicorn through requirements.txt file in my azure devops deployment pipeline. What could be going wrong here?

error

1

There are 1 answers

0
Ryan Hill On

So, I looked up uvicorn and I'm not exactly sure if it'll work in a blessed image. There may be some additional setup/configuration that has to be done.

But here's what I would try, follow Using GitHub Actions for Python Applications - Azure App Service and configure your pipeline as illustrated. Make sure you have SCM_DO_BUILD_DURING_DEPLOYMENT set to true. This will tell the platform to download and install what's in requirements.txt. If there are any additional setup (I don't know much about uvicorn) but you can do that in the POST_BUILD_COMMAND, see Customize build automation for details. If your app.py needs to be in /test (not sure why but...) the startup command should look something like uvicorn --bind=0.0.0.0 --timout 600 --chdir test app:app. If that doesn't work, have look at the app logs and checkout troubleshooting for most common issues and fixes.

If none of that is helpful, you can also configure your own custom container with uvicorn installed and configured to your liking and push the image to your web app.