-
-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathMakefile
More file actions
88 lines (64 loc) · 2.91 KB
/
Makefile
File metadata and controls
88 lines (64 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
TAGS_FILE = .tags
ifeq ($(CI),true)
DOCKER_EXEC_FLAGS = -T
else
DOCKER_EXEC_FLAGS = -it
endif
COMPOSE = docker compose
COMPOSE_EXEC = $(COMPOSE) exec $(DOCKER_EXEC_FLAGS)
bash: # Run bash inside `web` container
$(COMPOSE_EXEC) web bash
bash-root: # Run bash as root inside `web` container
$(COMPOSE_EXEC) -u root web bash
build: # Build containers and pull images
$(COMPOSE) pull
$(COMPOSE) build
build-ci:
# Remove definition of user as stated in <https://docs.github.com/en/actions/reference/workflows-and-actions/dockerfile-support#user>
sed -i '/^\s\?USER/d' Dockerfile
sed -i '/# Create a non-root user to run the app/,/&& chown -R django:django \/app/d' Dockerfile
sed -i '/^\s\+user:/d' compose.yml
$(COMPOSE) pull db messaging storage
$(COMPOSE) build web
build-no-cache: # Build containers without using cache
$(COMPOSE) pull
$(COMPOSE) build --no-cache
clean: stop # Stop and clean orphan containers
rm -f $(TAGS_FILE)
$(COMPOSE) down -v --remove-orphans
clear-cache: # Clear Django cache stored on Redis
$(COMPOSE_EXEC) web python manage.py clear_cache
dbshell: # Connect to database shell using `web` container
$(COMPOSE_EXEC) web python manage.py dbshell
help: # List all make commands
@awk -F ':.*#' '/^[a-zA-Z_-]+:.*?#/ { printf "\033[36m%-15s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) | sort
kill: # Force stop (kill) and remove containers
$(COMPOSE) kill
$(COMPOSE) rm --force
lint: # Run linter script
$(COMPOSE_EXEC) web /app/lint.sh
lint-check: # Run the linter without changing files
$(COMPOSE_EXEC) web /app/lint.sh --check
lint-check-ci:
$(COMPOSE) run --rm web bash -c '/app/lint.sh --check'
logs: # Show all containers' logs (tail)
$(COMPOSE) logs -tf
migrate: # Execute Django migrations inside `web` container
$(COMPOSE_EXEC) web python manage.py migrate
migrations: # Execute `makemigrations` inside `web` container
$(COMPOSE_EXEC) web python manage.py makemigrations
shell: # Execute Django shell inside `web` container
$(COMPOSE_EXEC) web python manage.py shell
restart: stop start # Stop all containers and start all containers in background
start: # Start all containers in background
$(COMPOSE) up -d
stop: # Stop all containers
$(COMPOSE) down
tags: # Generate tags file for the entire project (requires universal-ctags)
@git ls-files | ctags -L - --tag-relative=yes --quiet --append -f "$(TAGS_FILE)"
test: # Execute `pytest` and coverage report inside `web` container
$(COMPOSE_EXEC) web bash -c 'coverage run -m pytest $(TEST_ARGS) && coverage report'
test-ci:
$(COMPOSE) up -d db messaging storage
$(COMPOSE) run --rm web bash -c 'python manage.py create_buckets && coverage run -m pytest $(TEST_ARGS) && coverage report'
.PHONY: bash bash-root build build-ci build-no-cache clean clear-cache dbshell help kill lint lint-check lint-check-ci logs migrate migrations restart shell start stop tags test test-ci