Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
201 lines (160 loc) · 7.37 KB
/
Copy pathMakefile
File metadata and controls
201 lines (160 loc) · 7.37 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
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
all: usage
CWD=$(shell pwd)
PYTHON_VER:=3.11.3
PYTHON_VER_DIR:=$(shell pyenv root)/versions/$(PYTHON_VER)
VENV_NAME:=beorum-$(PYTHON_VER)
VENV_DIR:=$(shell pyenv root)/versions/$(VENV_NAME)
.PHONY: usage
usage: ## show usage for Make targets
@printf -- 'Available targets:\n\n'
@awk -F ':.*?## ' \
'/^[a-zA-Z]/ && NF==2 {printf " %-26s%s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
########################### Installing development base (Python & Node.js) ####################
.PHONY: python
python: $(PYTHON_VER_DIR) # install python version required by project
$(PYTHON_VER_DIR):
echo will install Python v.$(PYTHON_VER) into $(PYTHON_VER_DIR)
pyenv install $(PYTHON_VER)
########################### Creating/preparing development environment ########################
.PHONY: b-env
b-env: python $(VENV_DIR) ## [Backend ] create virtual environment for project
$(VENV_DIR):
@echo will install virtual environment $(VENV_NAME) into $(VENV_DIR)
pyenv virtualenv $(PYTHON_VER) $(VENV_NAME)
pyenv local $(VENV_NAME)
.PHONY: b-env-rm
b-env-rm: ## [Backend ] remove virtual environment of project
@echo will uninstall virtual environment $(VENV_NAME) from $(VENV_DIR)
pyenv uninstall -f $(VENV_NAME)
.PHONY: f-env
f-env: ## [Frontend] create environment for project
@echo will uninstall prettier as typescript formatter
( cd frontend/vite-project && \
npm install )
########################### Handling database #################################################
.PHONY: db-up-d
db-up-d: ## [Database] start database container (via docker)
docker compose up -d db
.PHONY: db-up-test-d
db-up-test-d: ## [Database] start testing database container (via docker)
docker compose up -d testdb
.PHONY: db-init-d
db-init-d: db-up-d # [Database] generate database and first migration via docker (first time only)
docker compose run dev aerich init-db
# `docker compose up db` will start Postgres available at localhost:5430
.PHONY: db-init
db-init: db-up-d ## [Database] generate database and first migration (first time only)
( cd backend && \
dotenv --file .env.localdev run -- aerich init-db )
.PHONY: db-make-migrations-d
db-make-migrations-d: db-up-d # [Database] create migration after schema change (via docker)
docker compose run dev aerich migrate
.PHONY: db-make-migrations
db-make-migrations: db-up-d ## [Database] create migration after schema change
( cd backend && \
dotenv --file .env.localdev run -- aerich migrate )
.PHONY: db-create-d
db-create-d: db-up-d # [Database] (re)generate database (to latest migration; via docker)
docker compose run dev aerich upgrade
.PHONY: db-create
db-create: db-up-d ## [Database] (re)generate database (to latest migration)
( cd backend && \
dotenv --file .env.localdev run -- aerich upgrade )
########################### Handling dependencies #############################################
.PHONY: b-deps-gen
b-deps-gen: b-env ## [Backend ] generate dependencies files without installing them
pip install --upgrade pip pip-tools
( cd backend && \
pip-compile --no-emit-index-url --resolver=backtracking && \
pip-compile --no-emit-index-url --resolver=backtracking requirements-dev.in )
.PHONY: b-deps
b-deps: b-deps-gen ## [Backend ] install dependencies needed to run the project
( cd backend && \
pip-sync requirements.txt requirements-dev.txt )
########################### Code formatting ###################################################
.PHONY: b-format
b-format: ## [Backend ] format code
( cd backend && \
isort . && \
black . && \
flake8 . )
.PHONY: f-format-check
f-format-check: ## [Frontend] check which files would be reformatted
( cd frontend/vite-project && \
npx prettier . --check )
.PHONY: f-format
f-format: ## [Frontend] format code
( cd frontend/vite-project && \
npx prettier . --write )
########################### Tests #############################################################
.PHONY: b-run-test
b-run-test: ## [Backend ] run tests locally
( cd backend && \
PYTHONPATH=./src/ pytest tests/ )
.PHONY: b-run-test-vv
b-run-test-vv: ## [Backend ] run tests locally (with verbose flag)
( cd backend && \
PYTHONPATH=./src/ pytest -vv tests/ )
.PHONY: d-test-b
d-test-b: ## [ Docker ] run tests of backend server
docker compose build dev && \
docker compose run --rm \
-e PYTHONDONTWRITEBYTECODE=1 dev pytest -p no:cacheprovider
########################### API editor ########################################################
.PHONY: api-editor-kill
api-editor-kill: # remove container hosting Swagger Editor
docker rm --force beorum-api-editor
.PHONY: api-editor
api-editor: api-editor-kill # run Swagger Editor on OpenAPI spec of Beorum API
docker run -d -p 8099:8080 --name beorum-api-editor -v ${CWD}/spec:/tmp -e SWAGGER_FILE=/tmp/beorum.yaml swaggerapi/swagger-editor
sleep 1
python -m webbrowser http://localhost:8099/
########################### Backend generator #################################################
.PHONY: api-svr-gen
api-svr-gen: # generate FastAPI server stub from OpenAPI spec of Beorum API
docker run --rm -v "${CWD}:/local" openapitools/openapi-generator-cli generate \
-i /local/spec/beorum.yaml \
-g python-fastapi \
-o /local/backend
sudo chown `whoami`:`id -g -n` -R backend
########################### Run and stop ######################################################
.PHONY: b-run
b-run: b-env db-up-d ## [Backend ] run FastAPI server at http://localhost:8085/docs (press Ctrl-C to quit)
PYENV_VERSION=beorum-$(PYTHON_VER) pyenv which pip
PYENV_VERSION=beorum-$(PYTHON_VER) pip install -r backend/requirements.txt
PYENV_VERSION=beorum-$(PYTHON_VER) pip list
python -m webbrowser http://localhost:8085/docs/
( cd backend && \
PYENV_VERSION=beorum-$(PYTHON_VER) PYTHONPATH=${PWD}/backend/src \
dotenv --file .env.localdev run -- uvicorn app.main:app --host 0.0.0.0 --port 8085 )
.PHONY: f-run
f-run: ## [Frontend] run Vite+React at http://localhost:3005/ (press q to quit)
( cd frontend/vite-project && \
python -m webbrowser http://localhost:3005/ && \
npm run dev -- --strictPort --port 3005 )
.PHONY: d-run
d-run: ## [ Docker ] run whole app (at http://localhost:3004/ + http://localhost:8084/docs + postgresql://localhost:5430/beorum)
@( echo ========================================================== && \
echo starting frontend at http://localhost:3004/ && \
echo starting backend at http://localhost:8084/docs && \
echo starting DB at postgresql://localhost:5430/beorum && \
echo ========================================================== && \
docker-compose up --build)
.PHONY: d-run-b
d-run-b: ## [ Docker ] run backend (at http://localhost:8084/docs)
( echo ========================================================== && \
echo starting backend at http://localhost:8084/docs && \
echo ========================================================== && \
docker-compose up backend)
.PHONY: d-run-f
d-run-f: ## [ Docker ] run frontend (at http://localhost:3004)
( echo ========================================================== && \
echo starting frontend at http://localhost:3004/ && \
echo ========================================================== && \
docker-compose up frontend)
.PHONY: d-stop
d-stop: ## [ Docker ] stop running containers and remove volumes, networks, etc.
docker compose down --rmi all --volumes --remove-orphans
.PHONY: d-clean
d-clean: d-stop ## [ Docker ] cleanup application (stop & remove everything)
docker compose rm