[PYTHON] Deploy from GitHub Actions to Azure App Service


During the Qiita Azure posting campaign, I've summarized how to deploy a GitHub repository to Azure because it's a good opportunity. It was surprisingly easy with the VS Code extension Deploy to Azure.


Use GitHub for the repository and Azure AppService for the deployment destination. Action of GitHub is used for linking from GitHub to Azure, but basically the extension of VS Code does it for you, so even first-time users can easily do it.


  1. Create a GitHub project
  2. Create Azure AppService resource
  3. Create an Action workflow on GitHub
  4. Push the source

Detailed procedure

1. Create a GitHub project

Create a GitHub repository. No special settings are required, so they will be omitted.

2. Create Azure AppService resource

Create a resource for the AppService to deploy to. Basically, it will be created in the Azure portal.

2.1. Log in to the portal and go to the App Service screen.


2.2. Click the Add button from the AppService screen to move to the resource creation screen.


2.3. Enter the information required to create the resource.


If you can create it properly, a screen like this will be displayed.


3. Create an Action workflow on GitHub

Since it is troublesome to manually write the yaml file used for Action on GitHub, I will use the extension of VS Code.

Clone the repository and add the source

Clone the GitHub repository and add the source you want to deploy.

Deploy to Azure installation

If you use VS Code's Deploy to Azure extension, it will automatically generate a yaml of Action on GitHub. Since it is troublesome to make yaml from 1, install Deploy to Azure.


Get an Access Token on GitHub

Since it is required for Deploy to Azure, get an AccessToken according to the following GitHub Docs. https://docs.github.com/ja/[email protected]/github/authenticating-to-github/creating-a-personal-access-token

Generating yaml to control GitHub Actions

3.1. Open the cloned directory with VS Code, open the command palette with Ctr + Shift + P, and execute the Deploy to Azure: Configure CI / CD Pipeline command. 3.2. You will be asked for the Access Token on GitHub, so enter the Access Token you obtained in advance. 3.3. You will be asked for the environment and subscription of the web service, so enter it. 3.4. The fourth input item should be the resource name of the Azure App Service created in 2, so select it.

If you enter so far, you should see `` `.github \ workflows \ workflow.yml``` in the open directory.

yaml fix

Depending on the environment, v1 actions may not be available, so modify azure / webapps-deploy @ v1 to azure / webapps-deploy @ v2.

4. Push the source

All you have created so far will be reflected in the GitHub repository. When you push the source, Action on GitHub will read yaml and execute it until deployment.

If you want to see the progress of Action, select the target repository on GitHub, click the Actions tab, and the workflow of Action is running with a commit message.

It is completed when it becomes as follows.



If you add code to this yaml, you can also automate the test. By the way, if the test fails, the Action will stop and it will not be deployed. The following is an example added when running pytest


    - name: pytest
      working-directory: .
      run: |
        pip install pytest
        pip install -r requirements.txt
        python -m pytest

in conclusion

I summarized how to deploy Azure. There is also a function called DevOps starter in Azure that allows you to do everything written here with GUI, but since the default was python2 and unnecessary things such as dashboard etc. came with it, I summarized this method that I can do as I like. ..

Recommended Posts

Deploy from GitHub Actions to Azure App Service
The story of switching the Azure App Service web system from Windows to Linux
Sample to put Python Flask web app on Azure App Service (Web App)
Deploy your Go app on Google App Engine with GitHub Actions
How to ssh into Azure App Service and enable venv
How to create a clone from Github
Build a command line app in Python to understand setup.py, argparse, GitHub Actions
How to clone github remote repository from atom
Sum from 1 to 10
Deploy a Python 3.6 / Django / Postgres web app on Azure
The wall of changing the Django service from Python 2.7 to Python 3
App development to tweet in Python from Visual Studio 2017
[Azure] Deploy locally created ML model to the cloud
How to use Azure Table storage from Django (PTVS)
Steps from installing Python 3 to creating a Django app
Deploy a Django app made with PTVS on Azure
Deploy a web app created with Streamlit to Heroku