How to deploy a .py file to an Azure Web App App Service using Git
This code will print Hello World to the Azure console every 30 seconds
import time
import logging
logging.basicConfig(level=logging.INFO)
while True:
logging.info("Hello, World!")
time.sleep(30)
This guide assumes the following
- You have an Azure Web app deployed with python and linux configured.
- Git is installed on your pc
- Python Is installed
- Open CMD on your PC and navigate to the directory of your .py project and run this command ONCE per project.
git init
- Then run this command to add all files to the repository
git add .
- This command will commit the files
git commit -m "Initial commit"
- We now need to configure the app to tell us where we can deploy.
- App > Deployment Center > Local Git > Save
- Copy the URL from the previous step and use the next command to tell out repository where to deploy
git remote add azure <gitUrl>
- This command lets us change the URL later if needed
git remote set-url azure <newGitUrl>
- Then navigate to the “Local Git/FTPS Credentials” tab and ensure there isn’t a yellow banner at the top of the page.
- If step 6 has the banner shown, navigate to Configuration > General Settings > Turn Basic Authentication “ON” > Save
- We will then run the following code and when it asks to authenticate use credentials from Deployment Center > Local Git/FTPS Credentials. The local git username and password.
git push azure master
- Lastly navigate to Configuration > General Settings.
- Set the Startup command to “
python <ScriptName>.py
” and save
- Set the Startup command to “
At this point if we check the log stream we should see the script running.