Local Development with Aldryn/Docker

So far, local development with Docker for Aldryn projects has been a pain.

  • Docker features a very slow build (5 to 10 minutes)
  • super slow page load / server response time. This might be acceptable for software development, but not for web development where much is try & refresh.
  • Docker also brought my 2015 8GB RAM 2.2GHz Intel i7 MacBook Air to its knees. It’s just not cool, wenn the fan is constantly on. No pun intended.
  • Also I found debugging through Docker with Pycharm to be a major pain, it was slow and eventually completely stopped working. Pycharm kept adding Docker containers and they ate up my system.
  • Last but not least not all of the syntax / symbol checks work in Pycharm through Docker

I wanted to be able to develop locally just like it works great for a non-Aldryn DjangoCMS project. Here is how I made Aldryn work for me:

Prerequisite: Fully working Aldryn Local / Docker (Docker Toolbox on Mac OS X) setup.

In docker-compose.yml make the db container expose its postgres port to the host system:

  - "5432:5432"
 image: postgres:9.4
  - ".:/app:rw"

Create a virtualenv

cd ~/Projects/projectname
mkvirtualenv projectname --python /usr/bin/python2.7

In postactivate of your new virtualenv add the following env vars. They are needed by the aldryn-django package.

export NGINX_CONF_PATH=/dummy/path/
export BASE_DIR=/your-path/Projects/projectname
# if your apps live in a separate folder add the path to PYTHONPATH
# In Pycharm, mark the folder that contains the apps as Source so that Django finds them.
export DEBUG=true
# make sure the IP is the one of your docker-machine (look it up with: docker-machine ip)
export DATABASE_URL="postgres://postgres@"
export CACHE_URL="locmem://"

then source postactivate or deactivate and workon projectname

Also there are a couple of packages that are required by Aldryn in a version that is not on pypi. I’ve added them to requirements.in:

# unresolved dependency if pip install manually

The requirements can now be installed:

pip install -r requirements.in

now, manage.py should already work.

Before the website works locally, you have to add the local static and media urls to urls.py:

if settings.DEBUG:
   from django.conf.urls.static import static
   urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
   urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

On the command line a ./manage.py runserver will now be able to start the Aldryn project.

In Pycharm a normal Django Server interpreter can now be set up (I serve env vars through a .env file).

A Pycharm Note: If your apps live in a separate folder (such as src) you need to flag this folder as additional source in pycharm (have a look at the project preferences).

Let me know whether you like this approach or if there is potential for optimisation.

One thought on “Local Development with Aldryn/Docker”

Comments are closed.