django CMS on Divio / Docker

This is for developers at what. that are new to the Divio world of django and django CMS. Welcome!

Below you will find a couple of hints that will hopefully make your life simpler in regards to handling django and django CMS projects with Divio hosting.

Divio Intro

First of all, get familiar with the Divio platform and download their tools:

Handle Deployment Failures on Divio

  • Grep for error in the Docker stdout (divio.com log)
  • When it works locally, but not on the cloud: put the local server into live configuration
  • How to provide cases to divio.com in case above doesn’t help: Push the state that causes problems to a separate branch and ping with a step by step reproduction instructions and the link to the branch.

Collaboration through Divio Control with your own git repository

Tip: Use gitlab or github or such and add your own repository to the project so you have full control over the repository.

How to run the frontend pipeline in Docker:

docker-compose run --rm web gulp watch --debug

But in general it’s better to run npm outside of the docker container in your host system, it’s more performant.

Migrations

docker-compose run --rm web python manage.py migrate

or if the container is already running:

docker-compose exec web python manage.py migrate

Performance

Are you on Mac OS X? First of all, open the Docker for Mac settings and release the docker machine from its pitiful state: Increase memory to 3GB and give it a second CPU (no need for additional GPU power though).

Adding django apps to your project

Rebuild the web container after adding a Django App:

docker-compose build web

Docker says no space left on device

docker system prune

Debug Aldryn Settings

docker-compose run --rm -e ALDRYN_ADDONS_DEBUG=True web python manage.py

This will give you a folder in

addons/.debug/

with the history of how settings are set by different aldryn modules.

Aldryn addons

Addons add some magic to every django CMS project. Especially to your settings. In order to debug the settings from addons you can add a print() statement for the settings after the following line to see what settings variables are already present from the addons:

aldryn_addons.settings.load(locals())

  • Settings are added in the order of how the addons are added to INSTALLED_ADDONS
  • Ssh into a docker container, run `env` to show all the env variables, many of these are picked up as settings.py variables.
  • You can copy and paste addons outside of the XML brackets in your settings.py and use them as normal pip packages, just be aware that every version has it’s own unique UUID in the package URL, so you cannot guess the URL of an addon package for a specific version you need to know it from Divio Control.

It’s best not to use aldryn addons anymore. Use pypi instead. It’s much simpler to develop using a minimum example django / django CMS setup in the package itself, so it can be installed in itself with the pip -e flag, also good for unit tests.

Access the docker postgres database

pycharm has a pretty ok database editor. You can connect to your docker database.

  1. Add this to your docker-compose.yml. This makes postgresql available on the docker machine’s IP address.
 ports:
  - "5432:5432"

Then reload the containers

docker-compose restart db