-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
296 lines (241 loc) · 7.99 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
RICHIE_SITE ?= funmooc
# -- Terminal colors
COLOR_INFO = \033[0;36m
COLOR_RESET = \033[0m
# -- Docker
DOCKER_UID = $(shell id -u)
DOCKER_GID = $(shell id -g)
NGINX_IMAGE_NAME = fundocker/openshift-nginx
NGINX_IMAGE_TAG = 1.13
COMPOSE = \
NGINX_IMAGE_NAME="$(NGINX_IMAGE_NAME)" \
NGINX_IMAGE_TAG="$(NGINX_IMAGE_TAG)" \
DOCKER_USER="$(DOCKER_UID):$(DOCKER_GID)" \
docker-compose
COMPOSE_RUN = $(COMPOSE) run --rm
COMPOSE_RUN_APP = $(COMPOSE_RUN) app-dev
COMPOSE_EXEC = $(COMPOSE) exec
COMPOSE_EXEC_APP = $(COMPOSE_EXEC) app-dev
COMPOSE_TEST_RUN = $(COMPOSE) run --rm -e DJANGO_CONFIGURATION=Test
COMPOSE_TEST_RUN_APP = $(COMPOSE_TEST_RUN) app-dev
WAIT_DB = $(COMPOSE_RUN) dockerize -wait tcp://db:5432 -timeout 60s
WAIT_ES = $(COMPOSE_RUN) dockerize -wait tcp://elasticsearch:9200 -timeout 60s
WAIT_SENTINEL = $(COMPOSE_RUN) dockerize -wait tcp://redis-sentinel:26379 -wait tcp://redis-primary:6379 -timeout 20s
# -- Node
# We must run node with a /home because yarn tries to write to ~/.yarnrc. If the
# ID of our host user (with which we run the container) does not exist in the
# container (e.g. 1000 exists but 1009 does not exist by default), then yarn
# will try to write to "/.yarnrc" at the root of the system and will fail with a
# permission error.
COMPOSE_RUN_NODE = $(COMPOSE_RUN) -e HOME="/tmp" node
YARN = $(COMPOSE_RUN_NODE) yarn
# -- Django
MANAGE = $(COMPOSE_RUN_APP) python manage.py
# -- Rules
default: help
bootstrap: \
env.d/aws \
data/media/$(RICHIE_SITE)/.keep \
data/db/$(RICHIE_SITE) \
stop \
build-front \
build \
i18n \
run \
migrate \
init
bootstrap: ## install development dependencies
.PHONY: bootstrap
# == Docker
build: ## build all containers
$(COMPOSE) build app
$(COMPOSE) build nginx
$(COMPOSE) build app-dev
.PHONY: build
reset: ## Remove database and local files
$(COMPOSE) stop
rm -Ir data/* || exit 0
$(COMPOSE) rm db
.PHONY: reset
down: ## stop & remove containers
@$(COMPOSE) down
.PHONY: down
logs: ## display app logs (follow mode)
@$(COMPOSE) logs -f app-dev
.PHONY: logs
run: ## start the wsgi (production) or development server
@$(COMPOSE) up -V -d redis-sentinel
@$(WAIT_SENTINEL)
@$(COMPOSE) up -d nginx
@$(COMPOSE) up -d app-dev
@$(WAIT_DB)
.PHONY: run
stop: ## stop the development server
@$(COMPOSE) stop
.PHONY: stop
info: ## get activated site info
@echo "RICHIE_SITE: $(COLOR_INFO)$(RICHIE_SITE)$(COLOR_RESET)"
.PHONY: info
# == Frontend
build-front: install-front build-ts build-sass ## build front-end application
.PHONY: build-front
build-sass: ## build Sass files to css
@$(YARN) build-sass
.PHONY: build-sass
build-sass-production: ## build Sass files to css (production mode)
@$(YARN) build-sass-production
.PHONY: build-sass-production
build-ts: ## build ts(x) files to js
@$(YARN) build-ts
.PHONY: build-ts
build-ts-production: ## build ts(x) files to js (production mode)
@$(YARN) build-ts-production
.PHONY: build-ts-production
install-front: ## install front-end dependencies
@$(YARN) install
.PHONY: install-front
install-front-production: ## install front-end dependencies (production mode)
@$(YARN) install --frozen-lockfile
.PHONY: install-front-production
lint-front-prettier: ## run prettier linter over ts(x) & scss files
@$(YARN) prettier
.PHONY: lint-front-prettier
lint-front-prettier-write: ## run prettier over ts(x) & scss files -- beware! overwrites files
@$(YARN) prettier-write
.PHONY: lint-front-prettier-write
lint-front-eslint: ## run eslint over ts files
@$(YARN) lint
.PHONY: lint-front-eslint
lint-front: ## run all linters frontend on sources
lint-front: \
lint-front-prettier-write \
lint-front-eslint
.PHONY: lint-front
test-back: ## run back-end tests
bin/pytest
.PHONY: test-back
watch-sass: ## watch changes in Sass files
@$(YARN) watch-sass
.PHONY: watch-sass
watch-ts: ## watch changes in js files
@$(YARN) watch-ts
.PHONY: watch-ts
# == AWS/Terraform
env.d/aws:
cp env.d/aws.dist env.d/aws
# == Django
check: ## perform django checks
@$(MANAGE) check
.PHONY: check
demo-site: ## create a demo site
@$(COMPOSE) up -d db
@$(WAIT_DB)
@$(MANAGE) flush
@$(MANAGE) create_demo_site
@${MAKE} search-index
.PHONY: demo-site
init: ## create base site structure
@$(MANAGE) richie_init
@${MAKE} search-index
.PHONY: init
# Nota bene: Black should come after isort just in case they don't agree...
lint-back: ## lint back-end python sources
lint-back: \
lint-back-isort \
lint-back-black \
lint-back-flake8 \
lint-back-pylint \
lint-back-bandit \
lint-back-raincoat
.PHONY: lint-back
lint-back-black: ## lint back-end python sources with black
@echo 'lint:black started…'
@$(COMPOSE_TEST_RUN_APP) black .
.PHONY: lint-back-black
lint-back-flake8: ## lint back-end python sources with flake8
@echo 'lint:flake8 started…'
@$(COMPOSE_TEST_RUN_APP) flake8
.PHONY: lint-back-flake8
lint-back-isort: ## automatically re-arrange python imports in back-end code base
@echo 'lint:isort started…'
@$(COMPOSE_TEST_RUN_APP) isort --atomic .
.PHONY: lint-back-isort
lint-back-pylint: ## lint back-end python sources with pylint
@echo 'lint:pylint started…'
@$(COMPOSE_TEST_RUN_APP) pylint .
.PHONY: lint-back-pylint
lint-back-raincoat: ## lint back-end python sources with raincoat
@echo 'lint:raincoat started…'
@$(COMPOSE_TEST_RUN_APP) raincoat
.PHONY: lint-back-raincoat
lint-back-bandit: ## lint back-end python sources with bandit
@echo 'lint:bandit started…'
@$(COMPOSE_TEST_RUN_APP) bandit -qr .
.PHONY: lint-back-bandit
import-fixtures: ## import fixtures
@$(MANAGE) import_fixtures -v3
.PHONY: import-fixtures
i18n: ## create/update translation files then compile them for both frontend and backend
i18n: \
i18n-back \
i18n-front
.PHONY: i18n
i18n-back: ## create/update .po files and compile .mo files used for i18n
@$(MANAGE) makemessages --keep-pot --all
@echo 'Reactivating obsolete strings (allow overriding strings defined in dependencies)'
@$(COMPOSE_RUN_APP) find ./ -type f -name django.po -exec sed -i 's/#~ //g' {} \;
@$(MANAGE) compilemessages
.PHONY: i18n-back
i18n-front: ## Extract and compile translation files used for react-intl
@$(YARN) extract-translations
@$(YARN) compile-translations
.PHONY: i18n-front
migrate: ## perform database migrations
@$(COMPOSE) up -d db
@$(WAIT_DB)
@$(MANAGE) migrate
.PHONY: migrate
search-index: ## (re)generate the Elasticsearch index
@$(COMPOSE) up -d elasticsearch
@$(WAIT_ES)
@$(MANAGE) bootstrap_elasticsearch
.PHONY: search-index
superuser: ## create a DjangoCMS superuser
@$(COMPOSE) up -d db
@$(WAIT_DB)
@$(MANAGE) createsuperuser
.PHONY: superuser
# == CI
ci-check: ## run django check management command on productin image
$(COMPOSE_RUN) app python manage.py check
.PHONY: ci-check
ci-migrate: ## run django migrate command on production image
@$(COMPOSE) up -d db
@$(WAIT_DB)
$(COMPOSE_RUN) app python manage.py migrate
.PHONY: ci-migrate
ci-run: ## start the wsgi server (and linked services)
@$(COMPOSE) up -d app
# As we use a remote docker environment, we should explicitly use the same
# network to check containers status
@echo "Wait for services to be up..."
docker run --network container:fun_db_1 --rm jwilder/dockerize -wait tcp://localhost:5432 -timeout 60s
docker run --network container:fun_elasticsearch_1 --rm jwilder/dockerize -wait tcp://localhost:9200 -timeout 60s
.PHONY: ci-run
ci-version: ## check version file bundled in the docker image
$(COMPOSE_RUN) --no-deps app cat version.json
.PHONY: ci-version
# == Misc
clean: ## restore repository state as it was freshly cloned
git clean -idx
.PHONY: clean
data/media/$(RICHIE_SITE)/.keep:
@echo 'Preparing media volume...'
@mkdir -p data/media/$(RICHIE_SITE)
@touch data/media/$(RICHIE_SITE)/.keep
data/db/$(RICHIE_SITE):
@echo 'Preparing db volume...'
@mkdir -p data/db/$(RICHIE_SITE)
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help