Cookiecutter for Django on docker using dokku in prod and docker-compose in dev and test.
- See OpenUp's development best practises
- See 12-factor App principles
- Projects are tested out of the box (including Continuous Integration (CI))
- Prefer stable versions of libraries and services
- prefer Long Term Support (LTS) versions
- Don't use the bleeding edge - wait until at least one point-release of a new major version.
- Same Dockerfile used for dev, test and prod
- Project directory named by
project_slug
- Django project directory named by
project_slug
- An initial app directory inside the django project directory named by
app_slug
- An initial app directory inside the django project directory named by
- Django project directory named by
- No non-vendor initial models or migrations
- Python dependency management via Pipenv
- Settings relating to security or the correct environment have no default and block startup to ensure they are set explicitly
- Passing tests
- Travis-CI
- Codecov.io code coverage reports for CI test runs
- Frontend assets
- Bundled using parcel
- Hashed and served using whitenoise in Django.
- Ensure it keeps working
- End-to-end test that creates and smoke-tests a basic project
- Ensure it's easy to maintain
- Ensure the choices made for projects it creates are explained
- Produce minimal boilerplate by default (lowest common denominator of what we consider well-configured apps) rather than producing everything possible just because it's easy to produce boilerplate using cookiecutter.
- See cookiecutter-django for more of a bleeding edge and experimental showcase of what's possible
Install cookiecutter
command line: pip install cookiecutter
- Install cookiecutter
- Run
cookiecutter gh:OpenUpSA/cookiecutter-django-dokku
- Answer the questions
- Initialise a git repository in yout project (
git init
) - Profit
To try it out quickly, just create a project im /tmp, accept all the defaults, run tree
and docker-compose
:
$ cookiecutter gh:OpenUpSA/cookiecutter-django-dokku -o /tmp
full_name [Your name]:
project_name [My site]: My Django Project
project_slug [my_django_project]:
app_slug [polls]: polls
...
$ tree /tmp/my_django_project/
/tmp/my_django_project/
├── docker-compose.yml
├── Dockerfile
├── manage.py
├── my_django_project
├── ├── admin.py
├── ├── initial_app
├── ├── ├── admin.py
...
$ docker-compose up
WARNING: The DJANGO_DEBUG_TOOLBAR variable is not set. Defaulting to a blank string.
Creating network "my_django_project_default" with the default driver
Creating volume "my_django_project_db-data" with default driver
Building web
Step 1/9 : FROM python:3.7-slim-buster
---> 5b03cb8574a0
Step 2/9 : ENV PYTHONUNBUFFERED 1
---> Using cache
---> 67ce14763e07
...
A fairly convenient dev workflow looks something like:
- Make a change
- In a shell in this directory, run
rm -rf /tmp/end_to_end_test/ && time bash -x tests/test_end_to_end.sh
- Do what you need to debug
- In a shell in
/tmp/end_to_end_test
, runcd . && docker-compose down --volumes
- You might need to add
--rmi local
to remove and rebuild images
- Rinse and repeat.
To modify default dependencies:
- Run the above to get an environment
- Get a root shell with something like
docker-compose run --rm -u root web bash
- Make your dependency changes using pipenv
- Outside the container, copy
Pipfile
andPipfile.lock
back to this repository - Test your changes using the end-to-end test approach above
This project is licensed under the terms of the MIT License