Example: Django
1 min
A Django site in the django folder of the project, served by Gunicorn behind nginx, with Poetry for the dependencies. See Project configuration for all settings.
clusterName: <cluster>
clusterRegion: eu-west-2
projectName: example
applications:
django:
type: python:nginx
appRoot: ./django
nginx:
version: "1.30"
environmentVariables:
NGINX_VHOST_PRESET: django
# nginx has its own copy of the code in /var/www/html, with the static
# files collected by the build hook.
NGINX_DJANGO_STATIC_ROOT: /var/www/html/static/
# Uploads are in the persistent storage, which nginx shares with Python.
NGINX_DJANGO_MEDIA_ROOT: /usr/src/app/media/
python:
version: "3.13"
port: 8080
environmentVariables:
BACKEND_HOST: "{{ django.host.0 }}"
DJANGO_SETTINGS_MODULE: myproject.settings
environmentFiles:
- ./.env.secrets
hooks:
build: |
pip install poetry
poetry install --no-interaction --no-root
poetry run python manage.py collectstatic --no-input
run: |
exec poetry run gunicorn myproject.wsgi:application --bind :8080
database:
excludeTablesFromImportOnDevEnvs:
- django_session
- auth_user
persistentStorages:
media: media
overrides:
- condition:
environments: [production]
hosts:
- example.comThings to know:
- The application connects to the database with the DB_* variables (DB_DRIVER is mysql or pgsql, by the database of the cluster). See Environment variables.
- python.port must be the port Gunicorn listens on. 8080 is the default, so you can leave it out.
- Run the migrations once after each deployment, i.e. in CI: hosty run <environment> -- poetry run python manage.py migrate --no-input. In the run hook they would run in every pod.
- Excluding auth_user keeps personal data out of development environments, but then they have no users: create one after the deployment.