-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
552 lines (462 loc) · 18.7 KB
/
Copy pathMakefile
File metadata and controls
552 lines (462 loc) · 18.7 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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# /!\ /!\ /!\ /!\ /!\ /!\ /!\ DISCLAIMER /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\
#
# This Makefile is only meant to be used for DEVELOPMENT purpose as we are
# changing the user id that will run in the container.
#
# PLEASE DO NOT USE IT FOR YOUR CI/PRODUCTION/WHATEVER...
#
# /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\
#
# Note to developers:
#
# While editing this file, please respect the following statements:
#
# 1. Every variable should be defined in the ad hoc VARIABLES section with a
# relevant subsection
# 2. Every new rule should be defined in the ad hoc RULES section with a
# relevant subsection depending on the targeted service
# 3. Rules should be sorted alphabetically within their section
# 4. When a rule has multiple dependencies, you should:
# - duplicate the rule name to add the help string (if required)
# - write one dependency per line to increase readability and diffs
# 5. .PHONY rule statement should be written after the corresponding rule
# ==============================================================================
# VARIABLES
BOLD := \033[1m
RESET := \033[0m
GREEN := \033[1;32m
# -- Database
DB_HOST = postgresql
DB_PORT = 5432
# -- Docker
# Get the current user ID to use for docker run and docker exec commands
ifeq ($(OS),Windows_NT)
DOCKER_USER := 0:0 # run containers as root on Windows
else
DOCKER_UID := $(shell id -u)
DOCKER_GID := $(shell id -g)
DOCKER_USER := $(DOCKER_UID):$(DOCKER_GID)
endif
COMPOSE = DOCKER_USER=$(DOCKER_USER) docker compose
COMPOSE_E2E = DOCKER_USER=$(DOCKER_USER) docker compose -f compose.yml -f compose-e2e.yml
COMPOSE_EXEC = $(COMPOSE) exec
COMPOSE_EXEC_APP = $(COMPOSE_EXEC) app-dev
COMPOSE_RUN = $(COMPOSE) run --rm
COMPOSE_RUN_APP = $(COMPOSE_RUN) app-dev
COMPOSE_RUN_CROWDIN = $(COMPOSE_RUN) crowdin crowdin
# -- Backend
MANAGE = $(COMPOSE_RUN_APP) python manage.py
PSQL_E2E = ./bin/postgres_e2e
MAIL_YARN = $(COMPOSE_RUN) -w //app/src/mail node yarn
# -- Frontend
PATH_FRONT = ./src/frontend
PATH_FRONT_ACCOUNTS = $(PATH_FRONT)/apps/accounts
FRONT_YARN = $(COMPOSE_RUN) -w //app/src/frontend node yarn
FRONT_E2E_YARN = $(COMPOSE_RUN) -w //app/src/frontend/apps/e2e node yarn
FRONT_ACCOUNTS_YARN = $(COMPOSE_RUN) -w //app/src/frontend/apps/accounts node yarn
FRONT_I18N_YARN = $(COMPOSE_RUN) -w //app/src/frontend/packages/i18n node yarn
FRONT_DEV_YARN = $(COMPOSE) run --rm --service-ports -w //app/src/frontend/apps/accounts node yarn
# -- Load tests
OIDC_LOADTEST_LOCUSTFILE = src/loadtests/oidc/locustfile.py
OIDC_LOADTEST_HOST ?= http://localhost:9901
OIDC_LOADTEST_PROFILE ?= mix-realistic
OIDC_LOADTEST_RESULTS_DIR ?= src/loadtests/oidc/results
OIDC_LOADTEST_CSV_PREFIX ?= $(OIDC_LOADTEST_RESULTS_DIR)/$(OIDC_LOADTEST_PROFILE)
OIDC_LOADTEST_CLIENT_ID ?= oidc-test-client
OIDC_LOADTEST_CLIENT_SECRET ?= oidc-test-secret
OIDC_LOADTEST_REDIRECT_URI ?= https://client.example.test/callback
OIDC_LOADTEST_SCOPE ?= openid email
OIDC_LOADTEST_PRECHECK_TIMEOUT ?= 5
OIDC_SLO_MAX_FAILURE_PCT ?= 1.0
OIDC_SLO_MAX_P95_MS ?= 1500
OIDC_SLO_MAX_P99_MS ?= 2500
# ==============================================================================
# RULES
default: help
data/media:
@mkdir -p data/media
data/static:
@mkdir -p data/static
# -- Project
create-env-local-files: ## create env.local files in env.d/development
create-env-local-files:
@touch env.d/development/crowdin.local
@touch env.d/development/common.local
@touch env.d/development/postgresql.local
@touch env.d/development/kc_postgresql.local
.PHONY: create-env-local-files
pre-bootstrap: \
data/media \
data/static \
create-env-local-files
.PHONY: pre-bootstrap
post-bootstrap: \
migrate \
demo \
back-i18n-compile \
mails-install \
mails-build
.PHONY: post-bootstrap
pre-beautiful-bootstrap: ## Display a welcome message before bootstrap
ifeq ($(OS),Windows_NT)
@echo ""
@echo "================================================================================"
@echo ""
@echo " Welcome to Accounts - User account management from La Suite!"
@echo ""
@echo " This will set up your development environment with:"
@echo " - Docker containers for all services"
@echo " - Database migrations and static files"
@echo " - Frontend dependencies and build"
@echo " - Environment configuration files"
@echo ""
@echo " Services will be available at:"
@echo " - Frontend: http://localhost:9900"
@echo " - API: http://localhost:9901"
@echo " - Admin: http://localhost:9901/admin"
@echo ""
@echo "================================================================================"
@echo ""
@echo "Starting bootstrap process..."
else
@echo "$(BOLD)"
@echo "╔══════════════════════════════════════════════════════════════════════════════╗"
@echo "║ ║"
@echo "║ 🚀 Welcome to Accounts - User account management from La Suite! 🚀 ║"
@echo "║ ║"
@echo "║ This will set up your development environment with : ║"
@echo "║ • Docker containers for all services ║"
@echo "║ • Database migrations and static files ║"
@echo "║ • Frontend dependencies and build ║"
@echo "║ • Environment configuration files ║"
@echo "║ ║"
@echo "║ Services will be available at: ║"
@echo "║ • Frontend: http://localhost:9900 ║"
@echo "║ • API: http://localhost:9901 ║"
@echo "║ • Admin: http://localhost:9901/admin ║"
@echo "║ ║"
@echo "╚══════════════════════════════════════════════════════════════════════════════╝"
@echo "$(RESET)"
@echo "$(GREEN)Starting bootstrap process...$(RESET)"
endif
@echo ""
.PHONY: pre-beautiful-bootstrap
post-beautiful-bootstrap: ## Display a success message after bootstrap
@echo ""
ifeq ($(OS),Windows_NT)
@echo "Bootstrap completed successfully!"
@echo ""
@echo "Next steps:"
@echo " - Visit http://localhost:9900 to access the application"
@echo " - Run 'make help' to see all available commands"
else
@echo "$(GREEN)🎉 Bootstrap completed successfully!$(RESET)"
@echo ""
@echo "$(BOLD)Next steps:$(RESET)"
@echo " • Visit http://localhost:9900 to access the application"
@echo " • Run 'make help' to see all available commands"
endif
@echo ""
.PHONY: post-beautiful-bootstrap
bootstrap: ## Prepare the project for local development
bootstrap: \
pre-beautiful-bootstrap \
pre-bootstrap \
build \
post-bootstrap \
run \
post-beautiful-bootstrap
.PHONY: bootstrap
bootstrap-e2e: ## Prepare Docker production images to be used for e2e tests
bootstrap-e2e: \
pre-bootstrap \
build-e2e \
back-i18n-compile \
run-e2e
.PHONY: bootstrap-e2e
# -- Docker/compose
build: cache ?=
build: ## build the project containers
@$(MAKE) build-backend cache=$(cache)
@$(MAKE) build-frontend cache=$(cache)
.PHONY: build
build-backend: cache ?=
build-backend: ## build the app-dev container
@$(COMPOSE) build app-dev $(cache)
.PHONY: build-backend
build-frontend: cache ?=
build-frontend: ## build the frontend container
@$(COMPOSE) build frontend-development $(cache)
.PHONY: build-frontend
build-e2e: cache ?=
build-e2e: ## build the e2e container
@$(MAKE) build-backend cache=$(cache)
@$(COMPOSE_E2E) build frontend $(cache)
.PHONY: build-e2e
down: ## stop and remove containers, networks, images, and volumes
@$(COMPOSE_E2E) down
rm -rf data/postgresql.e2e
.PHONY: down
logs: ## display app-dev logs (follow mode)
@$(COMPOSE) logs -f app-dev
.PHONY: logs
run-backend: ## Start only the backend application and all needed services
@$(COMPOSE) up --force-recreate -d nginx
.PHONY: run-backend
run: ## start the wsgi (production) and development server
run:
@$(MAKE) run-backend
@$(COMPOSE) up --force-recreate -d frontend-development
.PHONY: run
run-backend-e2e: ## start the backend for e2e tests (clean accounts_e2e DB + auth bypass)
@$(MAKE) stop
rm -rf data/postgresql.e2e
@ENV_OVERRIDE=e2e $(MAKE) run-backend
@ENV_OVERRIDE=e2e $(MAKE) migrate
.PHONY: run-backend-e2e
run-e2e-frontend: ## start only the e2e (production static) frontend
@$(COMPOSE_E2E) up --force-recreate -d frontend
.PHONY: run-e2e-frontend
run-e2e: ## start the full e2e stack (e2e backend + production frontend)
run-e2e:
@$(MAKE) run-backend-e2e
@$(MAKE) run-e2e-frontend
.PHONY: run-e2e
clear-db-e2e: ## quickly clears the e2e database, used between e2e tests
$(PSQL_E2E) -c "$$(cat bin/clear_db_e2e.sql)"
.PHONY: clear-db-e2e
run-tests-e2e: ## bring up the e2e stack and run the Playwright tests, example: make run-tests-e2e ARGS="--project=chromium --headed"
run-tests-e2e:
@$(MAKE) run-e2e
@cd src/frontend/apps/e2e && yarn test $(ARGS) $(filter-out $@,$(MAKECMDGOALS))
.PHONY: run-tests-e2e
ifneq ($(filter run-tests-e2e,$(MAKECMDGOALS)),)
RUN_TESTS_E2E_EXTRA_ARGS := $(filter-out run-tests-e2e,$(MAKECMDGOALS))
ifneq ($(RUN_TESTS_E2E_EXTRA_ARGS),)
$(RUN_TESTS_E2E_EXTRA_ARGS):
@:
endif
endif
status: ## an alias for "docker compose ps"
@$(COMPOSE_E2E) ps
.PHONY: status
stop: ## stop the development server using Docker
@$(COMPOSE_E2E) stop
.PHONY: stop
# -- Backend
demo: ## flush db then create a demo for load testing purpose
@$(MAKE) resetdb
@$(MANAGE) create_demo
.PHONY: demo
index: ## index all documents to remote search
@$(MANAGE) index
.PHONY: index
# Nota bene: Black should come after isort just in case they don't agree...
lint: ## lint back-end python sources
lint: \
lint-ruff-format \
lint-ruff-check \
lint-pylint
.PHONY: lint
lint-ruff-format: ## format back-end python sources with ruff
@echo 'lint:ruff-format started…'
@$(COMPOSE_RUN_APP) ruff format .
.PHONY: lint-ruff-format
lint-ruff-check: ## lint back-end python sources with ruff
@echo 'lint:ruff-check started…'
@$(COMPOSE_RUN_APP) ruff check . --fix
.PHONY: lint-ruff-check
lint-pylint: ## lint back-end python sources with pylint only on changed files from main
@echo 'lint:pylint started…'
bin/pylint --diff-only=origin/main
.PHONY: lint-pylint
test: ## run project tests
@$(MAKE) test-back-parallel
.PHONY: test
test-back: ## run back-end tests
@args="$(filter-out $@,$(MAKECMDGOALS))" && \
bin/pytest $${args:-${1}}
.PHONY: test-back
test-back-parallel: ## run all back-end tests in parallel
@args="$(filter-out $@,$(MAKECMDGOALS))" && \
bin/pytest -n auto $${args:-${1}}
.PHONY: test-back-parallel
makemigrations: ## run django makemigrations for the accounts project.
@echo "$(BOLD)Running makemigrations$(RESET)"
@$(COMPOSE) up -d postgresql
@$(MANAGE) makemigrations
.PHONY: makemigrations
migrate: ## run django migrations for the accounts project.
@echo "$(BOLD)Running migrations$(RESET)"
@$(COMPOSE) up -d postgresql
@$(MANAGE) migrate
.PHONY: migrate
superuser: ## Create an admin superuser with password "admin"
@echo "$(BOLD)Creating a Django superuser$(RESET)"
@$(MANAGE) createsuperuser --email admin@example.com --password admin
.PHONY: superuser
back-i18n-compile: ## compile the gettext files
@$(MANAGE) compilemessages --ignore=".venv/**/*"
.PHONY: back-i18n-compile
back-i18n-generate: ## create the .pot files used for i18n
@$(MANAGE) makemessages -a --keep-pot --all
.PHONY: back-i18n-generate
shell: ## connect to database shell
@$(MANAGE) shell #_plus
.PHONY: dbshell
# -- Database
dbshell: ## connect to database shell
docker compose exec app-dev python manage.py dbshell
.PHONY: dbshell
resetdb: FLUSH_ARGS ?=
resetdb: ## flush database and create a superuser "admin"
@echo "$(BOLD)Flush database$(RESET)"
@$(MANAGE) flush $(FLUSH_ARGS)
@${MAKE} superuser
.PHONY: resetdb
crowdin-download: ## Download translated message from crowdin
@$(COMPOSE_RUN_CROWDIN) download -c crowdin/config.yml
.PHONY: crowdin-download
crowdin-download-sources: ## Download sources from Crowdin
@$(COMPOSE_RUN_CROWDIN) download sources -c crowdin/config.yml
.PHONY: crowdin-download-sources
crowdin-upload: ## Upload source translations to crowdin
@$(COMPOSE_RUN_CROWDIN) upload sources -c crowdin/config.yml
.PHONY: crowdin-upload
i18n-compile: ## compile all translations
i18n-compile: \
back-i18n-compile \
frontend-i18n-compile
.PHONY: i18n-compile
i18n-generate: ## create the .pot files and extract frontend messages
i18n-generate: \
back-i18n-generate \
frontend-i18n-generate
.PHONY: i18n-generate
i18n-download-and-compile: ## download all translated messages and compile them to be used by all applications
i18n-download-and-compile: \
crowdin-download \
i18n-compile
.PHONY: i18n-download-and-compile
i18n-generate-and-upload: ## generate source translations for all applications and upload them to Crowdin
i18n-generate-and-upload: \
i18n-generate \
crowdin-upload
.PHONY: i18n-generate-and-upload
# -- Mail generator
mails-build: ## Convert mjml files to html and text
@$(MAIL_YARN) build
.PHONY: mails-build
mails-build-html-to-plain-text: ## Convert html files to text
@$(MAIL_YARN) build-html-to-plain-text
.PHONY: mails-build-html-to-plain-text
mails-build-mjml-to-html: ## Convert mjml files to html and text
@$(MAIL_YARN) build-mjml-to-html
.PHONY: mails-build-mjml-to-html
mails-install: ## install the mail generator
@$(MAIL_YARN) install
.PHONY: mails-install
# -- Misc
clean: ## restore repository state as it was freshly cloned
git clean -idx
.PHONY: clean
help:
@echo "$(BOLD)accounts Makefile"
@echo "Please use 'make $(BOLD)target$(RESET)' where $(BOLD)target$(RESET) is one of:"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(GREEN)%-30s$(RESET) %s\n", $$1, $$2}'
.PHONY: help
# Front
frontend-development-install: ## install the frontend locally
@$(FRONT_ACCOUNTS_YARN) install
.PHONY: frontend-development-install
frontend-lint: ## run the frontend linter
@$(FRONT_YARN) lint
.PHONY: frontend-lint
frontend-lint-fix: ## run the frontend linter with auto-fix option
@$(FRONT_YARN) lint-fix
.PHONY: frontend-lint-fix
run-frontend-development: ## Run the frontend in development mode
@$(COMPOSE) stop frontend-development
@$(FRONT_DEV_YARN) dev
.PHONY: run-frontend-development
frontend-test: ## Run the frontend tests
@$(FRONT_ACCOUNTS_YARN) test
.PHONY: frontend-test
frontend-i18n-extract: ## Extract the frontend translation inside a json to be used for crowdin
@$(FRONT_YARN) i18n:extract
.PHONY: frontend-i18n-extract
frontend-i18n-generate: ## Generate the frontend json files used for crowdin
frontend-i18n-generate: \
crowdin-download-sources \
frontend-i18n-extract
.PHONY: frontend-i18n-generate
frontend-i18n-compile: ## Format the crowin json files used deploy to the apps
@$(FRONT_YARN) i18n:deploy
.PHONY: frontend-i18n-compile
# -- K8S
build-k8s-cluster: ## build the kubernetes cluster using kind
./bin/start-kind.sh
.PHONY: build-k8s-cluster
start-tilt: ## start the kubernetes cluster using kind
tilt up -f ./bin/Tiltfile
.PHONY: build-k8s-cluster
bump-packages-version: VERSION_TYPE ?= minor
bump-packages-version: ## bump the version of the project - VERSION_TYPE can be "major", "minor", "patch"
@$(MAIL_YARN) version --no-git-tag-version --$(VERSION_TYPE)
@$(FRONT_YARN) version --no-git-tag-version --$(VERSION_TYPE)
@$(FRONT_E2E_YARN) version --no-git-tag-version --$(VERSION_TYPE)
@$(FRONT_ACCOUNTS_YARN) version --no-git-tag-version --$(VERSION_TYPE)
@$(FRONT_I18N_YARN) version --no-git-tag-version --$(VERSION_TYPE)
.PHONY: bump-packages-version
# -- Load tests
oidc-loadtest-mix-realistic: ## run OIDC full E2E loadtest with realistic mixed profile (70/30 default)
@$(MAKE) oidc-loadtest-profile OIDC_LOADTEST_PROFILE=mix-realistic
.PHONY: oidc-loadtest-mix-realistic
oidc-loadtest-nominal: ## run OIDC full E2E loadtest with nominal profile
@$(MAKE) oidc-loadtest-profile OIDC_LOADTEST_PROFILE=nominal
.PHONY: oidc-loadtest-nominal
oidc-loadtest-profile: ## run OIDC full E2E loadtest in headless mode for a given profile
@$(MAKE) oidc-loadtest-preflight
@$(MAKE) oidc-loadtest-setup
@mkdir -p $(OIDC_LOADTEST_RESULTS_DIR)
@OIDC_LOADTEST_PROFILE=$(OIDC_LOADTEST_PROFILE) uv run --with locust==2.42.1 \
locust -f $(OIDC_LOADTEST_LOCUSTFILE) --host=$(OIDC_LOADTEST_HOST) \
--headless --csv=$(OIDC_LOADTEST_CSV_PREFIX)
.PHONY: oidc-loadtest-profile
oidc-loadtest-preflight: ## fail fast if backend is down or upstream authorize is interactive
@uv run python src/loadtests/oidc/preflight.py \
--host $(OIDC_LOADTEST_HOST) \
--client-id $(OIDC_LOADTEST_CLIENT_ID) \
--redirect-uri $(OIDC_LOADTEST_REDIRECT_URI) \
--scope "$(OIDC_LOADTEST_SCOPE)" \
--timeout $(OIDC_LOADTEST_PRECHECK_TIMEOUT)
.PHONY: oidc-loadtest-preflight
oidc-loadtest-setup: ## create/update OAuth client used by OIDC loadtests
@$(MANAGE) setup_oidc_loadtest \
--client-id $(OIDC_LOADTEST_CLIENT_ID) \
--client-secret $(OIDC_LOADTEST_CLIENT_SECRET) \
--redirect-uri $(OIDC_LOADTEST_REDIRECT_URI)
.PHONY: oidc-loadtest-setup
oidc-loadtest-smoke: ## run OIDC full E2E loadtest with smoke profile
@$(MAKE) oidc-loadtest-profile OIDC_LOADTEST_PROFILE=smoke
.PHONY: oidc-loadtest-smoke
oidc-loadtest-ui: ## open Locust UI for OIDC full E2E loadtests
@$(MAKE) oidc-loadtest-preflight
@$(MAKE) oidc-loadtest-setup
@uv run --with locust==2.42.1 locust -f $(OIDC_LOADTEST_LOCUSTFILE) --host=$(OIDC_LOADTEST_HOST)
.PHONY: oidc-loadtest-ui
oidc-slo-check: ## validate OIDC SLO from Locust CSV output
@python src/loadtests/oidc/check_slo_from_csv.py \
--csv-prefix $(OIDC_LOADTEST_CSV_PREFIX) \
--max-failure-pct $(OIDC_SLO_MAX_FAILURE_PCT) \
--max-p95-ms $(OIDC_SLO_MAX_P95_MS) \
--max-p99-ms $(OIDC_SLO_MAX_P99_MS)
.PHONY: oidc-slo-check
oidc-slo-check-flows: ## validate OIDC SLO from Locust CSV including flow rows
@python src/loadtests/oidc/check_slo_from_csv.py \
--csv-prefix $(OIDC_LOADTEST_CSV_PREFIX) \
--max-failure-pct $(OIDC_SLO_MAX_FAILURE_PCT) \
--max-p95-ms $(OIDC_SLO_MAX_P95_MS) \
--max-p99-ms $(OIDC_SLO_MAX_P99_MS) \
--include-flow-rows
.PHONY: oidc-slo-check-flows