cookiecutter-django
cookiecutter-django copied to clipboard
Refine generated project Docker / Docker Compose infrastructure
Description
I've restructured our Docker / Docker Compose project template infrastructure.
Features
N.B. . denotes a generated project root directory.
-
./composehas been replaced with./docker:tree ./docker /docker ── caddy ├── Caddyfile └── Dockerfile ── django ├── Dockerfile └── scripts ├── celerybeat ├── celeryworker ├── django ├── django.local ├── entrypoint └── flower ── mailhog └── Dockerfile ── postgres ├── Dockerfile └── scripts ├── backup ├── backups ├── restore └── _sourced ├── constants.sh ├── countdown.sh ├── messages.sh └── yes_no.sh ── redis └── Dockerfile directories, 19 filesThere is now a single
Dockerfilefor every service we've got, where build instructions vary depending on anARG environment(its de-facto values arelocalandproductionfor now), for instance, this is how we're gonna be installingdjangorequirements from now on:UN [ "${environment}" = 'production' ] && pip --no-cache-dir install -r "./requirements/${environment}.txt" || pip install -r "./requirements/${environment}.txt"Also, I've extracted
mailhogandredisservice images to respectiveDockerfileallowing for image version parity betweenlocalandproductionDocker Compose environments. -
As for
./envs/*,tree -a ./.envs /.envs ── .caddy ── .django ── .django.local ── .postgres ── .postgres.local directories, 5 filesThose previously residing in
./.envs/local/were moved upwards and renamed to*.localto match./docker/**/scripts/*.localCMDscripts;./.envs/production/*env files were moved upwards as well. -
local.ymlandproduction.ymlservices'buildsections were extended with buildargs. Self-contained services -- those requiring no extra build artifacts but the ones from the correspondingDockerfileparent directory -- are now built in the context of the containing directory only.
Trade-offs to be Tackled
- [ ] I had to run
local.yml::services:celerybeatandproduction.yml::services:celerybeatwithuser: rootoverriding thedjangoUSERset in the base./docker/django/Dockerfile, otherwisecelerybeat.pid,celerybeat-scheduleand any other files created bycelery beatbinary cannot be modified by a beat process; this is a known problem, and a number of solutions exist but none of them seem portable enough to me. Any suggestions are welcome. UPD filesystem access is now restricted to all users other than root, effectively rendering this workaround regressive -- the only way to fix that is removingUSER djangoandchown ... django:djangofromdjangoDockerfile...
Rationale
Until now, generated project environments have been lacking parity, and therefore code execution consistency guarantees could not had been provided. Hope this PR will address that concern once and for all.
Use case(s) / visualization(s)
docker-compose -f local.yml build
docker-compose -f local.yml up
docker-compose -f production.yml build
docker-compose -f production.yml up
@pydanny, @jayfk, @luzfcb, @browniebroke, @sfdye thoughts?
@browniebroke since I last pushed here my go-to production Dockerfiles changed a bit: more optimizations and no more if/elses -- you'll like it ones I myself find time to update this PR :)