How to deploy a .py file to an Azure Web App App Service using Git

0

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

  1. Open CMD on your PC and navigate to the directory of your .py project and run this command ONCE per project.
    1. git init
  2. Then run this command to add all files to the repository
    1. git add .
  3. This command will commit the files
    1. git commit -m "Initial commit"
  4. We now need to configure the app to tell us where we can deploy.
    1. App > Deployment Center > Local Git > Save
  5. Copy the URL from the previous step and use the next command to tell out repository where to deploy
    1. git remote add azure <gitUrl>
      1. This command lets us change the URL later if needed
      2. git remote set-url azure <newGitUrl>
  6. Then navigate to the “Local Git/FTPS Credentials” tab and ensure there isn’t a yellow banner at the top of the page.
  7. If step 6 has the banner shown, navigate to Configuration > General Settings > Turn Basic Authentication “ON” > Save
  8. 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.
    1. git push azure master
  9. Lastly navigate to Configuration > General Settings.
    1. Set the Startup command to “python <ScriptName>.py” and save

At this point if we check the log stream we should see the script running.

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *