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 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/JasonFreeberg/Python-GitHub-Action.git
-
Load the local source code repo into VSCode:
cd Python-GitHub-Action code .
-
Create a virtual environment
# Linux/MacOS: python3 -m venv venv # Windows: py -m venv venv
VSCode will ask "We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?" Accept this prompt for better code completion.
-
Start the virtual environment
# Linux/MacOS source env/bin/activate # Windows .\venv\Scripts\activate
-
Install modules
pip install -r requirements.txt
-
Set up SQLite database
python manage.py makemigrations python manage.py migrate
-
Start the app locally
python 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.