Skip to content

stefsch/Python-GitHub-Action

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploy Django app to Azure App Service on Linux using GitHub Actions

This app is based off the official django tutorial. Using GitHub Actions, we can deploy this app directly to App Service after changes are pushed to the repo.

Prerequisites

  1. You need an Azure subscription to complete the tutorial. You can create a free account to start with: https://azure.microsoft.com/en-us/free/.

  2. You need to create a Python 3.7 Linux Web App.

  3. This web app requires a MySQL Server (django.db.backends.mysql) as the backend, you can also use PostgreSQL server as the backend. You can easily create a Azure Database for MySQL using Azure portal https://ms.portal.azure.com/#create/Microsoft.MySQLServer.

Prep the code

  1. Get the source code onto your dev machine:

    git clone https://github.com/yiliaomsft/pycon19-django.git 
  2. Load the local source code repo into VSCode:

    cd pycon19-django
    code
  3. Create a virtual environment

    # Linux/MacOS:
    python3 -m venv venv
    
    # Windows:
    py -m venv venv
  4. Install modules

    pip3 install -r requirements.txt
  5. Start the virtual environment

    # Linux/MacOS
    source env/bin/activate
    
    # Windows
    .\venv\Scripts\activate
  6. Start the app locally

    py manage.py runserver

Update database connection strings

The app currently uses a local SQLite database for local dev and test. You can deploy it with this, or wire it up to a proper MySQL database by editing settings.py to include your own database connection strings.

DATABASES = {
    'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': '<database name>',
            'USER': '<database user name>',
            'PASSWORD': 'database password',
            'HOST': 'database host',
    }
}

Deploy the django app to Linux App Service

Finally, get your Publish Profile of your webapp from the Azure Portal and add it as a secret in the GitHub web UI. The secret should be named "PUBLISH_PROFILE", to match the string in the workflow YAML.

About

Example repository for deploying to App Service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 65.2%
  • HTML 34.8%