]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Add a Makefile
authorStephen Finucane <stephen@that.guru>
Thu, 13 Sep 2018 17:13:20 +0000 (11:13 -0600)
committerStephen Finucane <stephen@that.guru>
Sun, 7 Jun 2026 18:05:23 +0000 (19:05 +0100)
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>
.gitignore
Makefile [new file with mode: 0644]

index 1282bc9fda86d8c290fbfc54c9f6ac8e4b179e0a..248b1bd4eaf9d0c3845a4373102a033a9404e26d 100644 (file)
@@ -58,3 +58,6 @@ patchwork/settings/production.py
 
 # django-dbbackup files
 /.backups
+
+# Makefile state files
+/.state
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..2374f51
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,44 @@
+MANAGE_PY := docker-compose run --rm web python manage.py
+
+default:
+       @echo "Call a specific subcommand"
+       @exit 1
+
+.state/docker-build: docker-compose.yml tools/docker/Dockerfile requirements-dev.txt
+       docker-compose build
+       mkdir -p .state
+       touch .state/docker-build
+
+build:
+       docker-compose build
+       mkdir -p .state
+       touch .state/docker-build
+
+serve: .state/docker-build
+       docker-compose up
+
+tests: .state/docker-build
+       docker-compose run -e TOXENV=${TOXENV} --rm web tox
+
+manage: .state/docker-build
+       $(MANAGE_PY) $(CMD)
+
+dbshell: .state/docker-build
+       $(MANAGE_PY) dbshell
+
+shell: .state/docker-build
+       $(MANAGE_PY) shell
+
+migrate: .state/docker-build
+       $(MANAGE_PY) migrate
+
+makemigrations: .state/docker-build
+       $(MANAGE_PY) makemigrations
+
+dbbackup: .state/docker-build
+       $(MANAGE_PY) dbbackup
+
+dbrestore: .state/docker-build
+       $(MANAGE_PY) dbrestore
+
+.PHONY: default build serve tests dbshell shell manage migrate makemigrations dbbackup dbrestore