-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
203 lines (164 loc) · 4.71 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
SHELL := /bin/bash
-include .env
VERSION := $(shell python -c "from supergood_reads import __version__; print(__version__)")
# ---------------------
# Setup
# ---------------------
# Create .env from template if .env doesn't already exist
.env:
cp -n ./tools/.env-sample .env
# Install pre-commit
.PHONY: install-pre-commit
install-pre-commit:
pre-commit install
.PHONY: install-nox
install-nox:
pip install --upgrade nox
.PHONY: setup
setup: .env install-pre-commit install-nox
# ---------------------
# QA
# ---------------------
# Lint all files using pre-commit
.PHONY: lint
lint:
nox -rs lint
# Scan dependencies for insecure packages
.PHONY: safety
safety:
nox -rs safety
# Run mypy type checking for python files.
.PHONY: mypy
mypy:
nox -rs mypy-3.11
# Run typescript type checking for typescript files.
.PHONY: tsc-check
tsc-check:
npx tsc --noEmit --incremental
# Run pytest via nox. Includes coverage check
.PHONY: pytest
pytest:
nox -rs "test-3.11(django_version='4.2')"
# Run pytest with debugger
.PHONY: debug-pytest
debug-pytest:
poetry run python -m debugpy --listen localhost:${DEBUGPY_PORT_PYTEST} --wait-for-client -m pytest
# Run frontend javascript tests with jest.
.PHONY: jest
jest:
npm run jest
# ---------------------
# Run on Local Machine
# ---------------------
# Install poetry dependencies
.PHONY: install
install:
poetry install --with dev,app
# Run django app
.PHONY: up
up:
poetry run python manage.py runserver ${PORT}
# Run vite static asset compilation dev server
.PHONY: vite
vite:
npm run dev
# Run django app with debugger enabled
.PHONY: debug-up
debug-up:
poetry run python -m debugpy --listen localhost:${DEBUGPY_PORT} manage.py runserver ${PORT}
# Start django python shell
.PHONY: shell
shell:
poetry run python manage.py shell_plus
# Start debugable python shell.
.PHONY: debug-shell
debug-shell:
poetry run python -m debugpy --listen localhost:${DEBUGPY_PORT} manage.py shell_plus
# Create a superuser for your django app
.PHONY: superuser
superuser:
poetry run python manage.py createsuperuser
# Start poetry venv
.PHONY: venv
venv:
source "$(poetry env info --path)/bin/activate"
# ---------------------
# Run on Docker
# ---------------------
DOCKER_COMPOSE_DIR := ./deploy/docker/compose
# Run your django app docker container
.PHONY: docker-up
docker-up:
docker compose \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.yml \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.local.yml \
--env-file .env \
up
# Run your production django app docker container
.PHONY: docker-up
docker-up-production:
docker compose \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.yml \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.production.yml \
--env-file .env \
up
# Kill and restart your django app docker container
.PHONY: docker-restart
docker-restart:
docker compose \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.yml \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.local.yml \
--env-file .env \
kill app
docker compose \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.yml \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.local.yml \
--env-file .env \
restart app
# Run a django app docker container without runserver
.PHONY: docker-troubleshoot
docker-troubleshoot:
docker compose \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.yml \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.local.yml \
-f ${DOCKER_COMPOSE_DIR}/docker-compose.troubleshooting.yml \
--env-file .env \
up
# Enter into the postgres db shell inside your running postgres container
.PHONY: db-shell
db-shell:
docker exec -it ${COMPOSE_PROJECT_NAME}-db-1 psql -U ${POSTGRES_USER} -p ${POSTGRES_PORT} -d ${POSTGRES_DB} -w
# Enter into a bash shell inside your running django app docker container
.PHONY: docker-shell
docker-shell:
docker exec -it ${COMPOSE_PROJECT_NAME}-app-1 /bin/bash
# Enter into the django python shell inside your running django app docker container
.PHONY: docker-shell-plus
docker-shell-plus:
docker exec -it ${COMPOSE_PROJECT_NAME}-app-1 python manage.py shell_plus
# ---------------------
# Build
# ---------------------
# collect static django assets
.PHONY: collectstatic
collectstatic:
poetry run python manage.py collectstatic --noinput
# compile vite assets for production
.PHONY: build-vite
build-vite:
npm run build
# Build "deploy/build/requirements/dev.txt"
.PHONY: dev-requirements
dev-requirements:
python ./deploy/scripts/build_requirements.py --dev
# Build "deploy/build/requirements/production.txt"
.PHONY: production-requirements
production-requirements:
python ./deploy/scripts/build_requirements.py
# Build local django app docker container
.PHONY: build-local
build-local:
sh ./deploy/scripts/build_image.sh local
# Build local django app docker container
build-production:
sh ./deploy/scripts/build_image.sh production