Dokku app.json example for Django

23 Feb · by Tim Kamanin · 2 min read

By default, Dokku understands only predeploy and postdeploy directives defined in app.json. To make it a little bit smarter, we need to install the dokku-require plugin:

dokku plugin:install https://github.com/crisward/dokku-require.git require

The plugin lets us declare plugins and volumes required by a Dokku app.

If declared plugin configuration or volume doesn't exist, dokku-require will create these for us during the deployment phase of the app.

You need to create the app.json file and put it in the root of your app repo:

{
  "dokku": {
    "plugins": [
        "postgres",
        "redis"
      ],
      "volumes": [
        {
          "host": "/var/lib/dokku/data/storage/$APP/media",
          "app": "/app/media",
          "phases": "deploy,run"
        },
        {
          "host": "/var/lib/dokku/data/storage/$APP/staticfiles",
          "app": "/app/staticfiles",
          "phases": "deploy,run"
        }
      ]
  },
  "scripts": {
    "dokku": {
      "predeploy": "python manage.py compress && python manage.py migrate --noinput",
      "postdeploy": "curl https://timonwe.com"
    }
  }
}

The following app.json example file defines:

  • plugins that describes required dokku services, for example, Postgres and Redis;
  • volumes that maps volumes from the host into a Dokku container, in case of Django, we want staticfiles and media directories to be persistent and available to the host Nginx server, so we map them to the host filesystem.
  • predeploy task that runs collectstatic and compress before the deployment happens;
  • postdeploy task that runs migrations after (and if) successful build has happened.

You can find dokku-require plugin docs here: https://github.com/crisward/dokku-require/blob/master/README.md.

Want to get more 🔥 tips like this one?

Subscribe to get notified about new dev tutorials

Comments