<leftside.dev>
<menu>
</menu>
<title>
Django Docker (WordPress CDN Plugin)
</title>
<content>

This is part of my series on building out my WordPress CDN plugin code.

While I'm trying to figure out my Stripe integration issues (Described here), I realised that I needed to convert my code base over to Docker in order to continue development on my new laptop.

I had originally developed it using Vagrant + VirtualBox, with Ansible for provisioning my servers. However, my new laptop is a Macbook that uses the newer M1 silicon. This makes my code will not run on my laptop, as VirtualBox is an x86 emulator, and not compatible with an ARM processor.

Not to worry, this will be a good excercise in converting over to Docker, which I can then use to form a containerised deployment architecture on one of the Cloud providers (still TBC).

To begin with, I used this Google Cloud example Dockerfile as a starting point, and basically copied my django code into that container.

This has been a relatively painless process, and more-or-less worked straight out of the box. I did have a few areas that needed attention in order to work:

  • I was previously relying on my PostgreSQL database running on the same machine as my django service. Moving that to a separate container meant I needed to slightly modify my DB connection details
  • I was using a number of environment variables that I was setting during Ansible provisioning. Docker has a simple way of setting environment variables which covers most of my needs, but I also created a .env file to set environment variables that I don't want to include in source control.
    When it comes time to deploy the application, I should be able to use some sort of "secret manager" that comes with container orchastration tools
  • I was previously running the django application through uWSGI, but have moved over to gunicorn, as that's the interface used in the example Dockerfile and seemed to be the easier option. This was a simple drop-in replacement, and didn't require any edits to my code

All-in-all, a simple transition for the back-end API.

When it comes time to deploy this API, I will put a productio NGINX box in front of the django app, using a simple proxy-pass configuration. Alternatively, the Cloud provider I choose might have some sort of API gateway-style functionality that I can use in place of NGINX, but we'll cross that bridge when we get to it.

</content>
</leftside.dev>