-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
96 lines (75 loc) · 2.16 KB
/
Makefile
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
89
90
91
92
93
94
95
96
COMPOSE := $(shell which docker-compose)
ifeq ($(COMPOSE),)
COMPOSE := docker compose
endif
COMPOSE_FILE := "docker-compose.dev.yml"
COMPOSE_CONTAINER_NAME := "peam_backend"
POSTGRES_COMPOSE_VOLUME := "peam-backend_local_postgres_data"
POSTGRES_COMPOSE_SERVICE := "postgres"
# Building and running
.PHONY: detached
detached:
${COMPOSE} -f ${COMPOSE_FILE} up -d
.PHONY: run
run:
${COMPOSE} -f ${COMPOSE_FILE} up
.PHONY: build
build:
${COMPOSE} -f ${COMPOSE_FILE} build
.PHONY: stop
stop:
${COMPOSE} -f ${COMPOSE_FILE} down
.PHONY: db
db:
${COMPOSE} -f ${COMPOSE_FILE} up -d ${POSTGRES_COMPOSE_SERVICE}
# Utilities
.PHONY: test
test: db
${COMPOSE} -f ${COMPOSE_FILE} run ${COMPOSE_CONTAINER_NAME} /bin/bash -c "export DJANGO_SETTINGS_MODULE=core.settings.test && \
pytest src"
.PHONY: format
format:
${COMPOSE} -f ${COMPOSE_FILE} run ${COMPOSE_CONTAINER_NAME} black .
.PHONY: lint
lint:
${COMPOSE} -f ${COMPOSE_FILE} run ${COMPOSE_CONTAINER_NAME} flake8 .
.PHONY: migration
migration:
${COMPOSE} -f ${COMPOSE_FILE} run ${COMPOSE_CONTAINER_NAME} python src/manage.py makemigrations
.PHONY: migrate
migrate:
${COMPOSE} -f ${COMPOSE_FILE} run ${COMPOSE_CONTAINER_NAME} python src/manage.py migrate
.PHONY: prune
prune: stop
docker volume rm ${POSTGRES_COMPOSE_VOLUME}
# Ease of usage
.PHONY: shell
shell:
${COMPOSE} -f ${COMPOSE_FILE} run ${COMPOSE_CONTAINER_NAME} python src/manage.py shell
.PHONY: bash
bash:
${COMPOSE} -f ${COMPOSE_FILE} run ${COMPOSE_CONTAINER_NAME} /bin/bash
.PHONY: fmtlint
fmtlint:
${COMPOSE} -f ${COMPOSE_FILE} run ${COMPOSE_CONTAINER_NAME} black . && flake8 .
.PHONY: create-admin-user
create-admin-user:
${COMPOSE} -f ${COMPOSE_FILE} run ${COMPOSE_CONTAINER_NAME} python src/manage.py create_admin_user \
--noinput \
--username admin \
--password admin \
--email [email protected]
.PHONY: create-db
create-db: stop prune db migrate
.PHONY: local-create-db
local-create-db: stop prune db
echo "Waiting for db..."
sleep 5
python src/manage.py makemigrations
python src/manage.py migrate
python src/manage.py setup_site
python src/manage.py create_admin_user \
--noinput \
--username admin \
--password admin \
--email [email protected]