Django on Docker development challenges

I finally had some time to do some deep work yesterday, and go my unversity project’s Django instance up and running. It took way to long. The local version settings for Cookiecutter Django work very easy from a Docker setup, but deploying them to a production instance took me by surprise. There were several issues I had to work through.

Cloud storage: I had inadvertently setup my project with the cloud storage settings for AWS. We’re not using either AWS or Google Cloud Services for CDN since this is just a small prototype. Since we didn’t have the AWS bucket credentials, the Django service wouldn’t start. I had to replay my setttings file to recreate my project without cloud services set to none. I attempted to use a fork of CC Django that uses Ngnix as the media server, but had other issues with it and decided we just won’t have media for this prototype.

Traefix: The production settings put Django behind a Traefik load balancer firewall, it’s configured to use Let’sEncrypt! for validation. Leaving this section blank causes Traefik to fail. So I commented out the SSL validation section of the configuration file. Currently it throws a warning about a nonexistent validator, but this is the only way to get it to serve pages. Currently. I’ll register with Let’sEncrypt!, but I’m not sure I’ll be able to procure a cert for our web server given that it’s a host on our University’s CS domain.

Developmental environment issues: Perhaps the most frustrating problems I’m having are around the way our environment is setup. I work off campus, yet our resource host is only available inside the campus network. I’m using our CS Gitlab server as a code repo, but I haven’t setup and CI jobs to deploy the code yet. On order for me to terminal to the server I have to SSH to our public CS server, then SSH to the resource server. In order to view the Django website, I have to open an RDS session. Not ideal, but I’ve yet to optimize the setup.

And troubleshooting these various problems with our production server comes with it’s own set of challenges. The git repo is synced to our Docker host, and the instance is deployed via docker-compose commands. In order for me to update the code, I have to cycle through down, build and up commands to resync the code. Hopefully, I’ll be able to setup Pycharm’s Docker remote capabilities to edit the code directly within the docker instance. We had planned to setup multiple containers in order to run a test server, but that’s going to be very difficult on a single host.

I’ve had other minor issues with production settings not taking properly. It looks like the .env files aren’t loading properly, causing the default local ones to be imported. I had to change the defaults in manage.py, but I assume this may break our local setup.

When everything is shaped up, I’ll have one git repo that can be run locally, in test or production, with a CI job that will deploy commits to our Docker container. I’ve got a lot of work to do.

Frustrations

I’m a bit perturbed right now. I went back to Django project I hadn’t worked on in two weeks and could not get my Pycharm interpreter working properly. I’d updated from the Community Edition to the Professional Edition during that time, which I’m not sure had anything to do with it, but this failed session brings me to another source of frustration with things that I need to get off my chest.

There are 3, maybe 4 ways that one might need to interact with a Django app in Pycharm. The first, being the Python console itself. The second, the regular command terminal. Third would be the various run configurations that one can setup. And four would be the Django console that Pycharm Pro enables. My issue is that each of these has their own environment variables settings! Maybe it’s just my inexperience showing through here, but I tend to use several of these when I’m working. I have a run configuration for the test server running, then the Django console for migrations and tests, and a terminal window that’s actually running the Django shell, so that I can muck around with code while I’m figuring things out.

I don’t know if I’m an idiot or what, but it just seems extremely ineffective, and I have got to be missing something.