Skip to content

Commit 398cc2c

Browse files
committed
Add a Makefile
Time to go old school. When using Docker, we can't simply use tox or manage.py command as commands should run inside the container and not on the host. To resolve this, we recommend using 'docker-compose run --rm web tox', which will run tox in the container. Having to remember these rather esoteric commands is annoying though (particularly when I haven't run it recently and therefore can't find the command with '<Ctrl>+R'). A series of make targets make this a heck of a lot easier for us. Note that this isn't ideal and won't entirely remove the need to run the above command. This is mostly due to how make is designed: namely, we need to pass positional arguments but each positional argument in make should be a target. This does, however, cover the biggest use cases and is therefore worth doing. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 4dda575 commit 398cc2c

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ patchwork/settings/production.py
5858

5959
# django-dbbackup files
6060
/.backups
61+
62+
# Makefile state files
63+
/.state

‎Makefile‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
MANAGE_PY := docker-compose run --rm web python manage.py
2+
3+
default:
4+
@echo "Call a specific subcommand"
5+
@exit 1
6+
7+
.state/docker-build: docker-compose.yml tools/docker/Dockerfile requirements-dev.txt
8+
docker-compose build
9+
mkdir -p .state
10+
touch .state/docker-build
11+
12+
build:
13+
docker-compose build
14+
mkdir -p .state
15+
touch .state/docker-build
16+
17+
serve: .state/docker-build
18+
docker-compose up
19+
20+
tests: .state/docker-build
21+
docker-compose run -e TOXENV=${TOXENV} --rm web tox
22+
23+
manage: .state/docker-build
24+
$(MANAGE_PY) $(CMD)
25+
26+
dbshell: .state/docker-build
27+
$(MANAGE_PY) dbshell
28+
29+
shell: .state/docker-build
30+
$(MANAGE_PY) shell
31+
32+
migrate: .state/docker-build
33+
$(MANAGE_PY) migrate
34+
35+
makemigrations: .state/docker-build
36+
$(MANAGE_PY) makemigrations
37+
38+
dbbackup: .state/docker-build
39+
$(MANAGE_PY) dbbackup
40+
41+
dbrestore: .state/docker-build
42+
$(MANAGE_PY) dbrestore
43+
44+
.PHONY: default build serve tests dbshell shell manage migrate makemigrations dbbackup dbrestore

0 commit comments

Comments
 (0)