Django app
This example deploys a Django demo app with dpl.
It covers five common tasks:
- run MariaDB
- create a database and user
- deploy a Django app with migrations
- serve the app and static files through nginx
- run a timer once per minute
Database server:
type: db-serverengine: mariadbversion: 12secret: db-rootDatabase:
type: dbserver: mariadbuser: demosecret: db-demoApp:
type: appimage: python:3.13-slim
builds: - files: ["requirements.txt"] script: | pip install --no-cache-dir -r requirements.txt
- files: ["*"] env: DB_NAME: ${db-demo:name} DB_USER: ${db-demo:user} DB_PASSWORD: ${db-demo:password} DB_HOST: ${db-demo:host} DB_PORT: ${db-demo:port} script: | python manage.py collectstatic --noinput mkdir -p /app/staticfiles
runtime: port: 8000 env: ALLOWED_HOSTS: "*" DJANGO_SECRET_KEY: django-demo-insecure-key DB_NAME: ${db-demo:name} DB_USER: ${db-demo:user} DB_PASSWORD: ${db-demo:password} DB_HOST: ${db-demo:host} DB_PORT: ${db-demo:port} init: | python manage.py migrate --noinput cmd: "gunicorn app.wsgi:application --bind 0.0.0.0:8000 --workers 2 --timeout 120"
exports: - source: /app/staticfiles path: /static
timers: - name: add-time schedule: "* * * * *" script: | python manage.py add_time --seconds 60HTTP server:
type: http-serverhttp_port: 8000https_port: falseDomain:
type: domainserver: nginxhosts: ["127.0.0.1"]routes: - kind: reverse_proxy location: / target: ${django-demo:url} - kind: serve_files location: /static root: ${django-demo:export}Run it
Section titled “Run it”Use DPL_BASE to point dpl at the demo directory:
export DPL_BASE="$PWD/django-demo"Create the secrets if you are starting from a clean copy:
dpl secret create db-rootdpl secret create db-demoCheck the units:
dpl check db-demodpl check django-demoStart dpl serve in another terminal:
DPL_BASE="$PWD/django-demo" dpl servePack the app into an archive, then deploy the database and the app:
tar -czf /tmp/django-demo.tar.gz -C django-demo/app .dpl deploy db-demodpl deploy django-demo /tmp/django-demo.tar.gzInspect the app:
dpl inspect django-demoOpen the site at:
http://127.0.0.1:8000If a build, the app, or a timer fails, check these logs:
django-demo/state/django-demo/log/build.logdjango-demo/state/django-demo/log/runtime.logdjango-demo/state/django-demo/log/timers.log