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.
-
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/.
-
You need to create a Python 3.7 Linux Web App.
-
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.
-
Get the source code onto your dev machine:
git clone https://github.com/yiliaomsft/pycon19-django.git
-
Load the local source code repo into VSCode:
cd pycon19-django code
-
Create a virtual environment
# Linux/MacOS: python3 -m venv venv # Windows: py -m venv venv
-
Install modules
pip3 install -r requirements.txt
-
Start the virtual environment
# Linux/MacOS source env/bin/activate # Windows .\venv\Scripts\activate
-
Start the app locally
py manage.py runserver
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',
}
}
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.