-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
182 lines (143 loc) · 7.04 KB
/
Copy pathMakefile
File metadata and controls
182 lines (143 loc) · 7.04 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
.PHONY: build test help
.DEFAULT_GOAL := help
export NODE_ENV ?= development
export DB_TENANT ?= default
ifneq "$(CI)" "true"
USER_ID = $(shell id -u)
GROUP_ID = $(shell id -g)
export UID = $(USER_ID)
export GID = $(GROUP_ID)
endif
help:
@grep -P '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# If the first argument is one of the supported commands...
SUPPORTED_COMMANDS := npm restore-db-dev _restore_db_dev restore-db-prod _restore_db_prod build import_units import_users import_sections import_unit_sections
SUPPORTS_MAKE_ARGS := $(findstring $(firstword $(MAKECMDGOALS)), $(SUPPORTED_COMMANDS))
ifneq "$(SUPPORTS_MAKE_ARGS)" ""
# use the rest as arguments for the command
COMMAND_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(COMMAND_ARGS):;@:)
endif
## Initialization ==============================================================
copy-conf: ## Initialize the configuration files by copying the *''-dist" versions (does not override existing config)
-cp -n ./config/${NODE_ENV}-dist.js ./config/${NODE_ENV}.js
ifeq ($(NODE_ENV), development)
-cp -n ./config/test-dist.js ./config/test.js
endif
install-npm-dependencies:
echo "Installing Node dependencies"
ifeq "$(CI)" "true"
docker compose -f docker-compose.dev.yml run --no-deps --rm api npm ci --legacy-peer-deps
else
docker compose -f docker-compose.dev.yml run --no-deps --rm api npm install --legacy-peer-deps
endif
install: copy-conf install-npm-dependencies ## Install npm dependencies for the node, admin, and frontend apps
## Production =================================================================
run-dist: ## Run the project in production mode using Docker images (i.e., without using the source code)
docker compose up --force-recreate
start-dist: run ## alias of make run-dist
## Deploy =================================================================
publish: build-prod ## publish version to docker hub
docker build -t cnrsinist/lodex:16.14.7 --build-arg http_proxy --build-arg https_proxy .
docker push cnrsinist/lodex:16.14.7
## Local Production Mode =================================================================
run-prod: build-prod ## Run the code in production mode
NODE_ENV=production docker compose -f docker-compose.prod.yml up --force-recreate
start-prod: run-prod ## Start the code in production mode (alias of make run-prod)
build-prod:
docker compose -f docker-compose.prod.yml build --build-arg http_proxy --build-arg https_proxy
## Development =================================================================
run-dev: ## Run the project in dev mode
NODE_ENV=development docker compose -f docker-compose.dev.yml up --force-recreate
start-dev: run-dev ## Start the project (alias of make run-dev)
build-app:
docker compose -f docker-compose.dev.yml run --no-deps --rm api npm run build
npm: ## allow to run dockerized npm command eg make npm 'install koa --save'
docker compose -f docker-compose.dev.yml run --no-deps --rm api npm $(COMMAND_ARGS)
## Tests =======================================================================
test-unit: ## Run the unit tests, usage : JEST_OPTIONS=myfile.to.test.spec.js make test-unit
## You can use other Jest options (https://jestjs.io/fr/docs/cli)
NODE_ENV=test docker compose -f docker-compose.dev.yml run --no-deps --rm api npm run test:unit -- $(JEST_OPTIONS)
test-unit-watch: ## Run the unit tests, usage : JEST_OPTIONS=myfile.to.test.spec.js make test-unit-watch
## You can use other Jest options (https://jestjs.io/fr/docs/cli)
NODE_ENV=test docker compose -f docker-compose.dev.yml run --no-deps --rm api npm run test:unit:watch -- $(JEST_OPTIONS)
test-e2e-start-dockers: ## Start the containers to use Cypress in interactive mode (with test-e2e-open-cypress)
ifeq "$(CI)" "true"
docker compose -f docker-compose.spec.yml up -d --build
else
docker compose -f docker-compose.spec.yml up --build
endif
test-e2e-logs:
docker compose -f docker-compose.spec.yml logs
test-e2e-logs-watch:
docker compose -f docker-compose.spec.yml logs -f
test-e2e-stop-dockers:
docker compose -f docker-compose.spec.yml down
test-e2e-open-cypress: ## Start the Cypress interactive interface
NODE_ENV=e2e npx cypress open
test-e2e:
ifeq "$(DISABLE_E2E_TESTS)" "true"
echo "E2E tests were disable because of the flag 'DISABLE_E2E_TESTS=true'"
else
$(MAKE) test-e2e-start-dockers
npx cypress install
./bin/wait-for -t 30 localhost:3000 -- npx cypress run --browser chrome || (\
$(MAKE) test-e2e-stop-dockers && \
exit 1)
endif
test-e2e-phase:
ifeq "$(DISABLE_E2E_TESTS)" "true"
echo "E2E tests were disable because of the flag 'DISABLE_E2E_TESTS=true'"
else
$(MAKE) test-e2e-start-dockers
npx cypress install
./bin/wait-for -t 30 localhost:3000 -- npm run test:e2e:${E2E_PHASE} || (\
$(MAKE) test-e2e-stop-dockers && \
exit 1)
endif
test: ## Run all tests
$(MAKE) test-unit
CI=true $(MAKE) test-e2e
## Data ========================================================================
mongo: ## Start the mongo database
docker compose up -d mongo
mongo-shell: ## Start the mongo shell
docker compose exec mongo mongosh lodex_${DB_TENANT}
mongo-shell-test: ## Start the mongo shell for the test database
docker compose exec mongo mongosh lodex_test_${DB_TENANT}
clear-npm: ## Clear all node_module diretories
docker compose -f docker-compose.dev.yml run --no-deps --rm api npm run clear
clear-database: ## Clear the whole database named by DB_TENANT (use "default" if missing)
docker compose exec mongo mongo lodex_${DB_TENANT} --eval " \
db.publishedDataset.deleteMany(); \
db.publishedCharacteristic.deleteMany(); \
db.field.deleteMany(); \
db.dataset.deleteMany(); \
db.publishedFacet.deleteMany(); \
db.subresource.deleteMany(); \
db.enrichment.deleteMany(); \
db.precomputed.deleteMany(); \
db.hiddenResource.deleteMany(); \
db.annotation.deleteMany(); \
"
clear-publication: ## Clear the published data, keep uploaded dataset and model in DB_TENANT (use "default" if missing)
docker compose exec mongo mongo lodex_${DB_TENANT} --eval " \
db.publishedDataset.deleteMany(); \
db.publishedCharacteristic.deleteMany(); \
db.publishedFacet.deleteMany(); \
"
clear-tenants: ## Clear all tenants databases in mongo
docker compose exec mongo mongo lodex_admin --eval "db.tenant.remove({});"
docker compose exec mongo mongo --quiet --eval 'db.getMongo().getDBNames().forEach(function(i){ if (i !== "lodex_admin") {db.getSiblingDB(i).dropDatabase()}})'
clear-docker: ## Clear containers, images & volumes created by docker
docker compose -f docker-compose.dev.yml down -v --remove-orphans --rmi all
docker compose -f docker-compose.prod.yml down -v --remove-orphans --rmi all
docker compose -f docker-compose.spec.yml down -v --remove-orphans --rmi all
docker compose -f docker-compose.yml down -v --remove-orphans --rmi all
@LODEX_IMAGES=$$(docker images -q cnrsinist/lodex); \
if [ -z "$$LODEX_IMAGES" ]; then \
echo "Aucune image cnrsinist/lodex trouvée."; \
else \
docker rmi $$LODEX_IMAGES; \
fi