-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
337 lines (212 loc) · 9.1 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# ENV defaults to local (so that requirements/local.txt are installed), but can be overridden
# (e.g. ENV=production make setup).
ENV ?= local
# PYTHON specifies the python binary to use when creating virtualenv
PYTHON ?= python3.8
# Editor can be defined globally but defaults to nano
EDITOR ?= nano
# By default we open the editor after copying settings, but can be overridden
# (e.g. EDIT_SETTINGS=no make settings).
EDIT_SETTINGS ?= yes
# Project name
PROJECT_NAME ?= knowledge_graphql_microservices
# Get root dir and project dir
PROJECT_ROOT ?= $(CURDIR)
SITE_ROOT ?= $(PROJECT_ROOT)/$(PROJECT_NAME)
BLACK ?= \033[0;30m
RED ?= \033[0;31m
GREEN ?= \033[0;32m
YELLOW ?= \033[0;33m
BLUE ?= \033[0;34m
PURPLE ?= \033[0;35m
CYAN ?= \033[0;36m
GRAY ?= \033[0;37m
COFF ?= \033[0m
# Mark non-file targets as PHONY
.PHONY: all help docker settings setup pycharm coverage node-install test clean quality eslint prospector stylelint docker-django
.PHONY: docker-manage shell makemigrations migrate docker-logs makemessages compilemessages add-locale psql isort isort-fix
.PHONY: build-pipenv-helper run-pipenv-helper pipenv-check pipenv-lock pipenv-install
.PHONY: django-shell node-shell node-quality
.PHONY: build-prettier-helper run-prettier prettier-check prettier-check-all prettier-format prettier-format-all
.PHONY: build-black-helper run-black black-check black-check-all black-format black-format-all
.PHONY: build-formatting-helpers
all: help
help:
@echo "+------<<<< Configuration >>>>------+"
@echo ""
@echo "ENV: $(ENV)"
@echo "PYTHON: $(PYTHON)"
@echo "PROJECT_ROOT: $(PROJECT_ROOT)"
@echo "SITE_ROOT: $(SITE_ROOT)"
@echo ""
@echo "+------<<<< Tasks >>>>------+"
@echo ""
@echo "$(CYAN)make setup$(COFF) - Sets up the project in your local machine"
@echo " This includes copying PyCharm files, creating local settings file, and setting up Docker."
@echo ""
@echo "$(CYAN)make pycharm$(COFF) - Copies default PyCharm settings (unless they already exist)"
@echo ""
@echo "$(CYAN)make test$(COFF) - Runs automatic tests on your python code"
@echo ""
@echo "$(CYAN)make coverage$(COFF) - Runs code test coverage calculation"
@echo ""
@echo "$(CYAN)make quality$(COFF) - Runs automatic code quality tests on your code"
@echo ""
@echo "$(CYAN)make isort-fix$(COFF) - Fix imports automatically with isort"
@echo ""
@echo "$(CYAN)make black-format-all$(COFF) - Format all Python code"
@echo ""
@echo "$(CYAN)make prettier-format-all$(COFF) - Format all JavaScript code"
@echo ""
build-pipenv-helper:
@docker build $(PROJECT_ROOT) -f Dockerfile-pipenv --tag $(PROJECT_NAME)_pipenv_wrapper
run-pipenv-helper: build-pipenv-helper
@docker run --rm --name $(PROJECT_NAME)_pipenv_wrapper -v $(PROJECT_ROOT):/src $(PROJECT_NAME)_pipenv_wrapper $(cmd)
@echo "Restoring file permissions"
@sudo chown `id -un`:`id -gn` $(PROJECT_ROOT)/Pipfile.lock $(PROJECT_ROOT)/Pipfile || echo "Missing sudo"
pipenv-lock:
@make run-pipenv-helper cmd="pipenv lock"
Pipfile.lock:
@make pipenv-lock
pipenv-check:
@make run-pipenv-helper cmd="pipenv check"
pipenv-install:
@make run-pipenv-helper cmd="pipenv install $(cmd)"
build-prettier-helper:
@docker build $(PROJECT_ROOT) -f $(PROJECT_ROOT)/.helpers/Dockerfile-prettier --tag $(PROJECT_NAME)_prettier_wrapper
run-prettier: build-prettier-helper
@docker run --rm --name $(PROJECT_NAME)_prettier_wrapper -v $(PROJECT_ROOT):/app $(PROJECT_NAME)_prettier_wrapper $(cmd)
prettier-check:
@make run-prettier cmd="prettier --check $(cmd)"
prettier-check-all:
@make prettier-check cmd="'app/src/**/*.{js,jsx,ts,tsx}'"
prettier-format:
@make run-prettier cmd="prettier --write $(cmd)"
prettier-format-all:
@make prettier-format cmd="'app/src/**/*.{js,jsx,ts,tsx}'"
build-black-helper:
@docker build $(PROJECT_ROOT) -f $(PROJECT_ROOT)/.helpers/Dockerfile-black --tag $(PROJECT_NAME)_black_wrapper
run-black: build-black-helper
@docker run --rm --name $(PROJECT_NAME)_black_wrapper -v $(PROJECT_ROOT):/app $(PROJECT_NAME)_black_wrapper $(cmd)
black-check:
@make run-black cmd="black --exclude fabfile.py\|docs\|local.py\|local_test.py --check $(cmd)"
black-check-all:
@make run-black cmd="black --exclude fabfile.py\|docs\|local.py\|local_test.py --check $(PROJECT_NAME)"
black-format:
@make run-black cmd="black --exclude fabfile.py\|docs\|local.py\|local_test.py $(cmd)"
black-format-all:
@make run-black cmd="black --exclude fabfile.py\|docs\|local.py\|local_test.py $(PROJECT_NAME)"
build-formatting-helpers: build-black-helper build-prettier-helper
docker: build-formatting-helpers settings
@docker-compose down
@docker-compose build
@docker-compose up -d
@docker-compose logs -f
setup: pycharm settings
@echo "$(CYAN)Creating Docker images$(COFF)"
@docker-compose build
@echo "$(CYAN)Running django migrations$(COFF)"
@make migrate
@echo "$(CYAN)===================================================================="
@echo "SETUP SUCCEEDED"
@echo "Run 'make docker' to start Django development server and Webpack.$(COFF)"
pycharm: $(PROJECT_ROOT)/.idea
$(PROJECT_ROOT)/.idea:
@echo "$(CYAN)Creating pycharm settings from template$(COFF)"
@mkdir -p $(PROJECT_ROOT)/.idea && cp -R $(PROJECT_ROOT)/.idea_template/* $(PROJECT_ROOT)/.idea/
settings: Pipfile.lock $(SITE_ROOT)/settings/local.py $(SITE_ROOT)/settings/local_test.py $(SITE_ROOT)/django.env
$(SITE_ROOT)/settings/local.py:
echo "$(CYAN)Creating Django local.py settings file$(COFF)"
cp $(SITE_ROOT)/settings/local.py.example $(SITE_ROOT)/settings/local.py
if [ $(EDIT_SETTINGS) = "yes" ]; then\
$(EDITOR) $(SITE_ROOT)/settings/local.py;\
fi
$(SITE_ROOT)/settings/local_test.py:
@echo "$(CYAN)Creating Django settings local_test.py file$(COFF)"
@cp $(SITE_ROOT)/settings/local_test.py.example $(SITE_ROOT)/settings/local_test.py
$(SITE_ROOT)/django.env:
@echo "$(CYAN)Creating Django .env file$(COFF)"
@touch $(SITE_ROOT)/django.env
coverage:
@echo "$(CYAN)Running automatic code coverage check$(COFF)"
@docker-compose run --rm django py.test --cov --cov-report term-missing
@docker-compose run --rm node yarn test -- --coverage
node-install:
@docker-compose run --rm node yarn
test-node-watch: clean
@docker-compose run --rm node yarn test -- --watchAll
test-node: clean
@echo "$(CYAN)Running automatic node.js tests$(COFF)"
@docker-compose run --rm node yarn test
test-django: clean
@echo "$(CYAN)Running automatic django tests$(COFF)"
@docker-compose run --rm django py.test
test: test-node test-django
clean:
@echo "$(CYAN)Cleaning pyc files$(COFF)"
@cd $(SITE_ROOT) && find . -name "*.pyc" -exec rm -rf {} \;
quality: prettier-check-all black-check-all node-quality prospector isort pipenv-check black-check-all
node-quality:
@echo "$(CYAN)Running Node Quality(COFF)"
@docker-compose run --rm node yarn quality
eslint:
@echo "$(CYAN)Running ESLint$(COFF)"
@docker-compose run --rm node yarn lint
prospector:
@echo "$(CYAN)Running Prospector$(COFF)"
@docker-compose run --rm django prospector
stylelint:
@echo "$(CYAN)Running StyleLint$(COFF)"
@docker-compose run --rm node yarn stylelint
isort:
@echo "$(CYAN)Checking imports with isort$(COFF)"
docker-compose run --rm django isort --recursive --check-only -p . --diff
isort-fix:
@echo "$(CYAN)Fixing imports with isort$(COFF)"
docker-compose run --rm django isort --recursive -p .
docker-django:
docker-compose run --rm django $(cmd)
django-shell:
docker-compose run --rm django /bin/sh
node-shell:
docker-compose run --rm node /bin/sh
docker-manage:
docker-compose run --rm django ./manage.py $(cmd)
shell:
docker-compose run --rm django ./manage.py shell
makemigrations:
docker-compose run --rm django ./manage.py makemigrations $(cmd)
migrate:
docker-compose run --rm django ./manage.py migrate $(cmd)
docker-logs:
docker-compose logs -f
makemessages:
docker-compose run --rm django ./manage.py makemessages -a
extract-i18n:
docker-compose run --rm node yarn extract-i18n
compilemessages:
docker-compose run --rm django ./manage.py compilemessages
start-services:
docker-compose -f docker-compose.services.yml up -d
stop-services:
docker-compose -f docker-compose.services.yml down
start-stack:
docker-compose -f docker-compose.stack.yml up -d
stop-stack:
docker-compose -f docker-compose.stack.yml down
ensure-local-dependencies:
@ pip install -r requirements/accounts.txt
@ pip install -r requirements/lists.txt
@ pip install -r requirements/products.txt
add-locale: $(SITE_ROOT)/locale
ifdef LOCALE
@echo "Adding new locale $(LOCALE)"
docker-compose run --rm django ./manage.py makemessages -l $(LOCALE)
docker-compose run --rm django ./manage.py makemessages -d djangojs -i node_modules -l $(LOCALE)
@echo "$(YELLOW)Also change the the ownership of the locale files to the current user:$(COFF)"
@echo ' - sudo chown -R $$USER: locale/ $(SITE_ROOT)/locale/'
else
@echo "$(RED)Please specify the locale you would like to add via LOCALE (e.g. make add-locale LOCALE='et')$(COFF)"
endif
psql:
docker-compose exec postgres psql --user $(PROJECT_NAME) --dbname $(PROJECT_NAME)