forked from apitable/apitable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
530 lines (422 loc) · 14.8 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
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
.DEFAULT_GOAL := help
PATH := node_modules/.bin:$(PATH)
SHELL := /bin/bash
ifndef UID
UID := $(shell id -u)
export UID
endif
ifndef GID
GID := $(shell id -g)
export GID
endif
ifndef ENV_FILE
ENV_FILE := .env
export ENV_FILE
endif
ifndef DEVENV_FILE
DEVENV_FILE := .env.devenv
export DEVENV_FILE
endif
ifndef DATA_PATH
DATA_PATH := ./
export DATA_PATH
endif
ifndef DEVENV_PROJECT_NAME
DEVENV_PROJECT_NAME := apitable-devenv
export DEVENV_PROJECT_NAME
endif
_DATAENV := docker compose --env-file $$ENV_FILE -p $$DEVENV_PROJECT_NAME -f docker-compose.yaml -f docker-compose.dataenv.yaml
_DEVENV := docker compose --env-file $$ENV_FILE -p $$DEVENV_PROJECT_NAME -f docker-compose.devenv.yaml
OS_NAME := $(shell uname -s | tr A-Z a-z)
ifeq ($(OS_NAME), darwin)
# macOS don't set user for some priviliges problem
RUNNER := $(_DEVENV) run --rm
else
# Not found
RUNNER := $(_DEVENV) run --rm --user $$UID:$$GID
endif
BUILDER := docker buildx bake
ttt:
echo $(OS_NAME)
echo $(RUNNER)
SEMVER3 := $(shell cat .version)
define ANNOUNCE_BODY
_____ _____ _______ _ _
/\ | __ \_ _|__ __| | | | |
/ \ | |__) || | | | __ _| |__ | | ___
/ /\ \ | ___/ | | | |/ _` | '_ \| |/ _ \
/ ____ \| | _| |_ | | (_| | |_) | | __/
/_/ \_\_| |_____| |_|\__,_|_.__/|_|\___|
APITable Makefile $(SEMVER3)
================================================================
endef
export ANNOUNCE_BODY
# define standard colors
ifneq (,$(findstring xterm,${TERM}))
BLACK := $(shell tput -Txterm setaf 0)
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
LIGHTPURPLE := $(shell tput -Txterm setaf 4)
PURPLE := $(shell tput -Txterm setaf 5)
BLUE := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
else
BLACK := ""
RED := ""
GREEN := ""
YELLOW := ""
LIGHTPURPLE := ""
PURPLE := ""
BLUE := ""
WHITE := ""
RESET := ""
endif
################################ build
build: ## build
make build-local
build-local:
make _pre-check
make _build-java
make _build-ts
_build-ts:
pnpm install
nx run-many -t build --exclude @apitable/datasheet
_build-java:
cd backend-server && ./gradlew build -x test --stacktrace
_pre-check:
make _check-web
_check-web:
pnpm install && pnpm build:dst:pre
pnpm lint:datasheet
_build-core:
pnpm install
nx run @apitable/core:build
################################ test
test: ## do test, unit tests, integration tests and so on.
make _test-ut-core-cov
test-e2e: ## start integration tests
pnpm run cy:run
test-e2e-open: ## start and debug integration tests
pnpm run cy:open
###### 【core unit test】 ######
_test-ut-core:
make _build-ts
pnpm run test:core
_test-ut-core-cov:
pnpm run test:core:cov
###### 【core unit test】 ######
###### 【room server unit test】 ######
SIKP_INITDB=false
_test_init_db:
@echo "${YELLOW}init-db initializing..${RESET}"
docker compose -f docker-compose.unit-test.yaml build test-init-db
docker compose -f docker-compose.unit-test.yaml run --rm test-init-db
@echo "${GREEN}initialize unit test db completed...${RESET}"
_test_clean: ## clean the docker in test step
docker rm -fv $$(docker ps -a --filter "name=test-.*" --format "{{.ID}}") || true
_test_docker_mysql: ## only run mysql container
docker compose -f docker-compose.unit-test.yaml up -d test-mysql
_test_dockers: ## run depends container in test step
docker compose -f docker-compose.unit-test.yaml up -d test-mysql ;\
docker compose -f docker-compose.unit-test.yaml up -d test-redis ;\
docker compose -f docker-compose.unit-test.yaml up -d test-rabbitmq
test-ut-room-local:
make _test_clean
docker compose -f docker-compose.unit-test.yaml up -d test-redis test-mysql test-rabbitmq
ifeq ($(SIKP_INITDB),false)
sleep 20
make _test_init_db
endif
make _build-ts
MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_USERNAME=apitable MYSQL_PASSWORD=password MYSQL_DATABASE=apitable_test MYSQL_USE_SSL=false \
DATABASE_TABLE_PREFIX=apitable_ \
REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_DB=4 REDIS_PASSWORD= \
RABBITMQ_HOST=127.0.0.1 RABBITMQ_PORT=5672 RABBITMQ_USERNAME=apitable RABBITMQ_PASSWORD=password \
INSTANCE_COUNT=1 APPLICATION_NAME=NEST_REST_SERVER \
pnpm run test:ut:room
make _test_clean
test-ut-room-docker:
@echo "${LIGHTPURPLE}Working dir, $(shell pwd)${RESET}"
@echo "${LIGHTPURPLE}$$(docker compose version)${RESET}"
make _test_clean
make _test_dockers
sleep 20
make _test_init_db
docker compose -f docker-compose.unit-test.yaml build unit-test-room
docker compose -f docker-compose.unit-test.yaml run --rm \
-e MYSQL_HOST=test-mysql \
-e REDIS_HOST=test-redis \
-e RABBITMQ_HOST=test-rabbitmq \
unit-test-room pnpm run test:ut:room:cov
@echo "${GREEN}finished unit test, clean up images...${RESET}"
_clean_room_coverage:
if [ -d "./packages/room-server/coverage" ]; then \
sudo chown -R $(shell id -u):$(shell id -g) ./packages/room-server/coverage; \
fi
make _test_clean
rm -fr ./packages/room-server/coverage || true
###### 【backend server unit test】 ######
test-ut-backend-docker:
@echo "$$(docker compose version)"
make _test_clean
make _test_dockers
sleep 20
make _test_init_db
make test-ut-backend-run
@echo "${GREEN}finished unit test, clean up images...${RESET}"
make _test_clean
test-ut-backend-run:
cd backend-server ;\
DATABASE_TABLE_PREFIX=apitable_ \
MYSQL_HOST=127.0.0.1 \
MYSQL_PORT=3306 \
MYSQL_USERNAME=apitable \
MYSQL_PASSWORD=password \
MYSQL_DATABASE=apitable_test \
REDIS_HOST=127.0.0.1 \
REDIS_PORT=6379 \
REDIS_PASSWORD= \
RABBITMQ_HOST=127.0.0.1 \
RABBITMQ_PORT=5672 \
RABBITMQ_USERNAME=apitable \
RABBITMQ_PASSWORD=password \
./gradlew testCodeCoverageReport --stacktrace
###### 【backend server unit test】 ######
###### 【init-db test】 ######
test-init-db-docker:
@echo "${LIGHTPURPLE}Working dir, $(shell pwd)${RESET}"
@echo "${LIGHTPURPLE}$$(docker compose version)${RESET}"
make _test_clean
make _test_docker_mysql
sleep 20
make _test_init_db
@echo "${GREEN}finished testing, clean up images...${RESET}"
buildpush-docker: ## build all and push all to hub.docker.io registry
echo $$APITABLE_DOCKER_HUB_TOKEN | docker login -u apitable --password-stdin || true;\
$(BUILDER) $(target) --push
.PHONY: build
build-docker: ## build all containers
$(BUILDER) $(target) --load
.PHONY: _build-init-db
_build-docker-init-db:
$(BUILDER) init-db
.PHONY: _build-backend-server
_build-docker-backend-server:
$(BUILDER) backend-server
###### development environtments ######
define RUN_LOCAL_TXT
Which service do you want to start run?
1) backend-server
2) room-server
3) web-server
4) databus-server
endef
export RUN_LOCAL_TXT
define RUN_PERF_TXT
*NOTE* You must build a package before profiling it.
Which service do you want to start run?
1) room-server / production mode / Clinic.js flamegraph
2) room-server / production mode / Clinic.js doctor
3) room-server / production mode / Clinic.js heapprofiler
4) room-server / production mode / Clinic.js bubbleprof
endef
export RUN_PERF_TXT
_check_env: ## check if .env files exists
@FILE=$$ENV_FILE ;\
if [ ! -f "$$FILE" ]; then \
echo "$$FILE does not exist. Please 'make env' first" ;\
exit 1 ;\
fi
run: _check_env ## run local code to development environemnt with docker env
make run-local
.PHONY: run-local
run-local: ## run services with local programming language envinroment
@echo "$$RUN_LOCAL_TXT"
@read -p "ENTER THE NUMBER: " SERVICE ;\
if [ "$$SERVICE" = "1" ]; then make _run-local-backend-server; fi ;\
if [ "$$SERVICE" = "2" ]; then make _run-local-room-server; fi ;\
if [ "$$SERVICE" = "3" ]; then make _run-local-web-server; fi ;\
if [ "$$SERVICE" = "4" ]; then make _run-docker-databus-server; fi
.PHONY: run-perf
run-perf: ## run room-server with local programming language envinroment for performance profiling
@echo "$$RUN_PERF_TXT"
@read -p "ENTER THE NUMBER: " SERVICE ;\
if [ "$$SERVICE" = "1" ]; then export PERF_TYPE=flame; make _run-perf-local-room-server; fi; \
if [ "$$SERVICE" = "2" ]; then export PERF_TYPE=doctor; make _run-perf-local-room-server; fi; \
if [ "$$SERVICE" = "3" ]; then export PERF_TYPE=heapprofiler; make _run-perf-local-room-server; fi; \
if [ "$$SERVICE" = "4" ]; then export PERF_TYPE=bubbleprof; make _run-perf-local-room-server; fi
_run-local-backend-server:
source scripts/export-env.sh $$ENV_FILE;\
source scripts/export-env.sh $$DEVENV_FILE;\
cd backend-server ;\
./gradlew build -x test ;\
MYSQL_HOST=127.0.0.1 \
REDIS_HOST=127.0.0.1 \
RABBITMQ_HOST=127.0.0.1 \
java -jar application/build/libs/application.jar
_run-local-room-server:
source scripts/export-env.sh $$ENV_FILE;\
source scripts/export-env.sh $$DEVENV_FILE;\
pnpm run start:room-server
_run-perf-local-room-server:
source scripts/export-env.sh $$ENV_FILE;\
source scripts/export-env.sh $$DEVENV_FILE;\
pnpm run start:room-server:perf:$$PERF_TYPE
_run-local-web-server:
source scripts/export-env.sh $$ENV_FILE;\
source scripts/export-env.sh $$DEVENV_FILE;\
rm -rf packages/datasheet/web_build;\
pnpm run sd
_run-docker-databus-server:
$(_DATAENV) up databus-server
define DEVENV_TXT
Which devenv do you want to start run?
0) UP ALL
1) backend-server
2) room-server
3) web-server
endef
export DEVENV_TXT
.PHONY: devenv
devenv: ## debug all devenv services with docker compose up -d
@echo "$$DEVENV_TXT"
@read -p "ENTER THE NUMBER: " DEVENV_NUMBER ;\
if [ "$$DEVENV_NUMBER" = "0" ]; then make devenv-up; fi ;\
if [ "$$DEVENV_NUMBER" = "1" ]; then make devenv-backend-server; fi ;\
if [ "$$DEVENV_NUMBER" = "2" ]; then make devenv-room-server; fi ;\
if [ "$$DEVENV_NUMBER" = "3" ]; then make devenv-web-server; fi
.PHONY: devenv-up
devenv-up:
$(_DEVENV) up -d
.PHONY: devenv-down
devenv-down: ## debug all devenv services with docker compose up -d
$(_DEVENV) down -v --remove-orphans
devenv-logs: ## follow all devenv services logs
$(_DEVENV) logs -f
devenv-ps:
$(_DEVENV) ps
.PHONY: devenv-backend-server
devenv-backend-server:
$(RUNNER) backend-server java -jar application/build/libs/application.jar
.PHONY: devenv-web-server
devenv-web-server:
$(RUNNER) web-server sh -c "pnpm run install && pnpm run sd"
.PHONY: devenv-room-server
devenv-room-server:
$(RUNNER) room-server pnpm run start:room-server
.PHONY: install
install: install-local
@echo 'Install Finished'
.PHONY: install-local
install-local: ## install all dependencies with local programming language environment
pnpm install && pnpm build:dst:pre
pnpm build:sr
cd backend-server && ./gradlew build -x test --stacktrace
.PHONY: install-docker
install-docker: _install-docker-web-server _install-docker-backend-server _install-docker-room-server ## install all dependencies with docker devenv
@echo 'Install Finished'
.PHONY: _install-docker-backend-server
_install-docker-backend-server:
$(RUNNER) backend-server ./gradlew build -x test
.PHONY: _install-docker-web-server
_install-docker-web-server:
$(RUNNER) web-server sh -c "pnpm run install && pnpm run build"
.PHONY: _install-docker-room-server
_install-docker-room-server:
$(RUNNER) room-server sh -c "pnpm run install && pnpm run build"
.PHONY:
clean: ## clean and delete git ignore and dirty files
git clean -fxd
###### buildpush ######
# bumpversion
.PHONY: patch
patch: # bump version number patch
docker run --rm -it --user $(shell id -u):$(shell id -g) -v "$(shell pwd):/app" apitable/bumpversion:latest bumpversion patch
.PHONY: minor
minor: # bump version number patch
docker run --rm -it --user $(shell id -u):$(shell id -g) -v "$(shell pwd):/app" apitable/bumpversion:latest bumpversion minor
.PHONY: major
major: # bump version number patch
docker run --rm -it --user $(shell id -u):$(shell id -g) -v "$(shell pwd):/app" apitable/bumpversion:latest bumpversion major
### data environement
.PHONY: dataenv
dataenv: _check_env
make dataenv-up
DATAENV_SERVICES := mysql minio redis rabbitmq init-db init-appdata
.PHONY: dataenv-up
dataenv-up: _dataenv-volumes
$(_DATAENV) up -d $(DATAENV_SERVICES)
_dataenv-volumes: ## create data folder with current user permissions
mkdir -p $$DATA_PATH/.data/mysql \
$$DATA_PATH/.data/minio/data \
$$DATA_PATH/.data/minio/config \
$$DATA_PATH/.data/redis \
$$DATA_PATH/.data/rabbitmq \
dataenv-down:
$(_DATAENV) down -v --remove-orphans
dataenv-ps:
$(_DATAENV) ps
dataenv-logs:
$(_DATAENV) logs -f
### production environment
.PHONY: up
up: _dataenv-volumes ## startup the application
@echo "Please execute 'make pull' first to download & upgrade all images to your machine."
docker compose up -d
.PHONY: down
down: ## shutdown the application
docker compose down -v --remove-orphans
.PHONY:ps
ps: ## docker compose ps
docker compose ps
### docker stuffs
.PHONY: pull
pull: ## pull all containers and ready to up
docker compose pull
######################################## init-db
INIT_DB_DOCKER_PATH=apitable/init-db
db-plan: ## init-db dry update
cd init-db ;\
docker build -f Dockerfile . --tag=${INIT_DB_DOCKER_PATH}
docker run --rm --env-file $$ENV_FILE -e ACTION=updateSQL --network apitable_default ${INIT_DB_DOCKER_PATH}
db-apply: ## init-db update database structure (use .env)
cd init-db ;\
docker build -f Dockerfile . --tag=${INIT_DB_DOCKER_PATH}
docker run --rm --env-file $$ENV_FILE -e ACTION=update --network apitable_default ${INIT_DB_DOCKER_PATH}
changelog: ## make changelog with github api
@read -p "GITHUB_TOKEN: " GITHUB_TOKEN;\
read -p "FROM[default:latest-tag]: " GIT_FROM ;\
read -p "TO[default:HEAD]: " GIT_TO ;\
if [ "$$GIT_FROM" = "" ]; then GIT_FROM=$(shell git describe --tags $$(git rev-list --tags --max-count=1)) ; fi ;\
if [ "$$GIT_TO" = "" ]; then GIT_TO=HEAD ; fi ;\
echo "" ;\
echo "FROM: $$GIT_FROM" ;\
echo "TO: $$GIT_TO" ;\
npx github-changelog-builder --token $$GITHUB_TOKEN -o apitable -r apitable -f $$GIT_FROM -t $$GIT_TO -a CHANGELOG.md
.PHONY: settings
settings: ## settings and l10n init
make _l10n
.PHONY: _l10n
_l10n: ## l10n apitable-ce
bash ./scripts/language-generate.sh ./packages/i18n-lang/src ./packages/l10n/gen ./packages/l10n/base ./packages/i18n-lang/src ./
bash ./scripts/l10n.sh ./packages/i18n-lang/src ./packages/l10n/gen ./packages/l10n/base ./packages/l10n/base ./
pnpm run build
### help
.PHONY: search
search:
@echo " "
@read -p "Search Command:" s; \
echo && grep -E "$$s.*?## .*" $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}';
@echo ' ';
@read -p "What do you want?>>" command; \
make $$command;
.PHONY: help
help:
@echo "$$ANNOUNCE_BODY"
@echo ' ';
@grep -E '^[0-9a-zA-Z-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}';
@echo ' '
@read -p "What do you want?>> " command; \
make $$command;