-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
326 lines (252 loc) · 11.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
# Determine this makefile's path.
# Be sure to place this BEFORE `include` directives, if any.
# THIS_FILE := $(lastword $(MAKEFILE_LIST))
THIS_FILE := $(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
#################################
# Documentation targets
#################################
SBTX = ./sbtx
.PHONY: docs-build
docs-build: ## build docs into the local 'site' folder
@$(MAKE) -C docs graphvizfigures
mkdocs build --strict
.PHONY: docs-serve
docs-serve: ## serve docs for local viewing
@$(MAKE) -C docs graphvizfigures
mkdocs serve
.PHONY: docs-install-requirements
docs-install-requirements: ## install requirements
pip3 install -r docs/requirements.txt
.PHONY: docs-clean
docs-clean: ## cleans the project directory
@rm -rf site/
.PHONY: structurizer
structurizer: ## starts the structurizer and serves c4 architecture docs
@docker pull structurizr/lite
@docker run -it --rm -p 8080:8080 -v $(CURRENT_DIR)/docs/architecture:/usr/local/structurizr structurizr/lite
#################################
# Docker targets
#################################
.PHONY: build
build: docker-build ## build all targets (excluding docs)
# add DOCKER_BUILDKIT=1 to enable buildkit logging as info
# https://github.com/sbt/sbt-native-packager/issues/1371
.PHONY: docker-build-dsp-api-image
docker-build-dsp-api-image: # build and publish dsp-api docker image locally
export DOCKER_BUILDKIT=1; $(SBTX) "webapi / Docker / publishLocal"
.PHONY: docker-publish-dsp-api-image
docker-publish-dsp-api-image: # publish dsp-api image to Dockerhub
export DOCKER_BUILDKIT=1; $(SBTX) "webapi / Docker / publish"
.PHONY: docker-build-sipi-image
docker-build-sipi-image: # build and publish sipi docker image locally
export DOCKER_BUILDKIT=1; $(SBTX) "sipi / Docker / publishLocal"
.PHONY: docker-publish-sipi-image
docker-publish-sipi-image: # publish sipi image to Dockerhub
export DOCKER_BUILDKIT=1; $(SBTX) "sipi / Docker / publish"
.PHONY: docker-build
docker-build: docker-build-dsp-api-image docker-build-sipi-image ## build and publish all Docker images locally
.PHONY: docker-publish
docker-publish: docker-publish-dsp-api-image docker-publish-sipi-image ## publish all Docker images to Dockerhub
.PHONY: docker-image-tag
docker-image-tag: ## prints the docker image tag
@$(SBTX) -Dsbt.log.noformat=true -Dsbt.supershell=false -Dsbt.ci=true -error "print dockerImageTag"
#################################
## DSP Stack Targets
#################################
.PHONY: stack-up
stack-up: docker-build ## starts the dsp-stack: fuseki, sipi, api and app.
@docker compose -f docker-compose.yml up -d db
$(CURRENT_DIR)/webapi/scripts/wait-for-db.sh
@docker compose -f docker-compose.yml up -d
$(CURRENT_DIR)/webapi/scripts/wait-for-api.sh
.PHONY: stack-up-fast
stack-up-fast: docker-build-dsp-api-image ## starts the dsp-stack by skipping rebuilding most of the images (only api image is rebuilt).
docker-compose -f docker-compose.yml up -d
.PHONY: stack-up-ci
stack-up-ci: KNORA_WEBAPI_TRIPLESTORE_FUSEKI_REPOSITORY_NAME := knora-test-unit
stack-up-ci: docker-build ## starts the dsp-stack using 'knora-test-unit' repository: fuseki, sipi, api.
docker-compose -f docker-compose.yml up -d
.PHONY: stack-restart
stack-restart: ## re-starts the dsp-stack: fuseki, sipi, api.
@docker compose -f docker-compose.yml down
@docker compose -f docker-compose.yml up -d db
$(CURRENT_DIR)/webapi/scripts/wait-for-db.sh
@docker compose -f docker-compose.yml up -d
$(CURRENT_DIR)/webapi/scripts/wait-for-api.sh
.PHONY: stack-restart-api
stack-restart-api: ## re-starts the api. Usually used after loading data into fuseki.
docker-compose -f docker-compose.yml restart api
@$(CURRENT_DIR)/webapi/scripts/wait-for-api.sh
.PHONY: stack-logs
stack-logs: ## prints out and follows the logs of the running dsp-stack.
@docker compose -f docker-compose.yml logs -f
.PHONY: stack-logs-db
stack-logs-db: ## prints out and follows the logs of the 'db' container running in dsp-stack.
@docker compose -f docker-compose.yml logs -f db
.PHONY: stack-logs-db-no-follow
stack-logs-db-no-follow: ## prints out the logs of the 'db' container running in dsp-stack.
@docker-compose -f docker-compose.yml logs db
.PHONY: stack-logs-sipi
stack-logs-sipi: ## prints out and follows the logs of the 'sipi' container running in dsp-stack.
@docker compose -f docker-compose.yml logs -f sipi
.PHONY: stack-logs-sipi-no-follow
stack-logs-sipi-no-follow: ## prints out the logs of the 'sipi' container running in dsp-stack.
@docker compose -f docker-compose.yml logs sipi
.PHONY: stack-logs-api
stack-logs-api: ## prints out and follows the logs of the 'api' container running in dsp-stack.
@docker compose -f docker-compose.yml logs -f api
.PHONY: stack-logs-api-no-follow
stack-logs-api-no-follow: ## prints out the logs of the 'api' container running in dsp-stack.
@docker compose -f docker-compose.yml logs api
.PHONY: stack-health
stack-health:
curl -f 0.0.0.0:3333/health
.PHONY: stack-status
stack-status:
@docker compose -f docker-compose.yml ps
.PHONY: stack-down
stack-down: ## stops the dsp-stack.
@docker compose -f docker-compose.yml down
.PHONY: stack-down-delete-volumes
stack-down-delete-volumes: clean-local-tmp clean-sipi-tmp ## stops the dsp-stack and deletes any created volumes (deletes the database!).
@docker compose -f docker-compose.yml down --volumes
.PHONY: stack-config
stack-config:
@docker compose -f docker-compose.yml config
.PHONY: stack-without-api
stack-without-api: stack-up ## starts the dsp-stack without dsp-api: fuseki and sipi only.
@docker compose -f docker-compose.yml stop api
.PHONY: stack-without-app
stack-without-app: stack-up ## starts the dsp-stack without dsp-app - this is the previous state of "make stack-up" command.
@docker compose -f docker-compose.yml stop app
.PHONY: stack-without-api-and-sipi
stack-without-api-and-sipi: stack-up ## starts the dsp-stack without dsp-api and sipi: fuseki only.
@docker compose -f docker-compose.yml stop api
@docker compose -f docker-compose.yml stop sipi
.PHONY: stack-db-only
stack-db-only: ## starts only fuseki.
@docker compose -f docker-compose.yml up -d db
$(CURRENT_DIR)/webapi/scripts/wait-for-db.sh
#################################
## Test Targets
#################################
.PHONY: test-all
test-all: test integration-test
.PHONY: test
test: ## runs all unit tests
$(SBTX) -v coverage "webapi/test" coverageAggregate
.PHONY: integration-test
integration-test: docker-build-sipi-image ## runs all integration tests
$(SBTX) -v coverage "integration/test" coverageAggregate
#################################
## Database Management
#################################
.PHONY: init-db-test
init-db-test: stack-down-delete-volumes stack-db-only ## initializes the knora-test repository
@echo $@
cd $(CURRENT_DIR)/webapi/scripts && ./fuseki-init-knora-test.sh
.PHONY: init-db-test-minimal
init-db-test-minimal: stack-down-delete-volumes stack-db-only ## initializes the knora-test repository with minimal data
@echo $@
cd $(CURRENT_DIR)/webapi/scripts && ./fuseki-init-knora-test-minimal.sh
.PHONY: init-db-test-empty
init-db-test-empty: stack-down-delete-volumes stack-db-only ## initializes the knora-test repository with minimal data
@echo $@
cd $(CURRENT_DIR)/webapi/scripts && ./fuseki-init-knora-test-empty.sh
.PHONY: init-db-from-test
init-db-from-test: ## init local database with data from test server. Use as `make init-db-from-test PW=database-password`
@echo $@
${MAKE} init-db-from-env ENV=db.test.dasch.swiss
.PHONY: init-db-from-test-dump
init-db-from-test-dump: ## init local database with data from local dump file of test server. Use as `make init-db-from-test-dump`
@echo $@
${MAKE} init-db-from-dump-file DUMP=db.test.dasch.swiss.trig
.PHONY: init-db-from-stage
init-db-from-stage: ## init local database with data from stage server. Use as `make init-db-from-stage PW=database-password`
@echo $@
${MAKE} init-db-from-env ENV=db.stage.dasch.swiss
.PHONY: init-db-from-stage-dump
init-db-from-stage-dump: ## init local database with data from local dump file of stage server. Use as `make init-db-from-stage-dump`
@echo $@
${MAKE} init-db-from-dump-file DUMP=db.stage.dasch.swiss.trig
.PHONY: init-db-from-prod
init-db-from-prod: ## init local database with data from prod server. Use as `make init-db-from-prod PW=database-password`
@echo $@
${MAKE} init-db-from-env ENV=db.dasch.swiss
.PHONY: init-db-from-prod-dump
init-db-from-prod-dump: ## init local database with data from local dump file of prod server. Use as `make init-db-from-prod-dump`
@echo $@
${MAKE} init-db-from-dump-file DUMP=db.dasch.swiss.trig
.PHONY: init-db-from-dev
init-db-from-dev: ## init local database with data from dev. Use as `make init-db-from-dev PW=database-password`
@echo $@
${MAKE} init-db-from-env ENV=db.dev.dasch.swiss
.PHONY: init-db-from-dev-dump
init-db-from-dev-dump: ## init local database with data from local dump file of dev server. Use as `make init-db-from-dev-dump`
@echo $@
${MAKE} init-db-from-dump-file DUMP=db.dev.dasch.swiss.trig
.PHONY: init-db-from-ls-test-server
init-db-from-ls-test-server: ## init local database with data from ls-test-server. Use as `make init-db-from-ls-test-server PW=database-password`
@echo $@
${MAKE} init-db-from-env ENV=db.ls-test-server.dasch.swiss
.PHONY: init-db-from-ls-test-server-dump
init-db-from-ls-test-server-dump: ## init local database with data from local dump file of ls-test-server server. Use as `make init-db-from-ls-test-server-dump`
@echo $@
${MAKE} init-db-from-dump-file DUMP=db.ls-test-server.dasch.swiss.trig
.PHONY: db-dump
db-dump: ## Dump data from an env. Use as `make db-dump PW=database-password ENV=db.0000-test-server.dasch.swiss`
@echo $@
@echo dumping environment ${ENV}
@curl -X GET -H "Accept: application/trig" -u "admin:${PW}" "https://${ENV}/dsp-repo" > "${ENV}.trig"
.PHONY: init-db-from-dump-file
init-db-from-dump-file: ## init local database from a specified dump file. Use as `make init-db-from-dump-file DUMP=some-dump-file.trig`
@echo $@
@echo dump file: ${DUMP}
${MAKE} init-db-test-empty
@curl -X POST -H "Content-Type: application/sparql-update" -d "DROP ALL" -u "admin:test" "http://localhost:3030/knora-test"
@curl -X POST -H "Content-Type: application/trig" -T "${CURRENT_DIR}/${DUMP}" -u "admin:test" "http://localhost:3030/knora-test"
.PHONY: init-db-from-env
init-db-from-env: ## ## Dump data from an env and upload it to the local DB. Use as `make init-db-from-env PW=database-password ENV=db.0000-test-server.dasch.swiss`
@echo $@
${MAKE} db-dump
${MAKE} init-db-from-dump-file DUMP=${ENV}.trig
#################################
## Other
#################################
clean-docker: ## cleans the docker installation
@docker system prune -af
@docker volume prune -f
.PHONY: clean-local-tmp
clean-local-tmp:
@rm -rf .tmp
@mkdir .tmp
.PHONY: clean-metals
clean-metals: ## clean SBT and Metals related stuff
@rm -rf .bloop
@rm -rf .bsp
@rm -rf .metals
@rm -rf target
@$(SBTX) "clean"
.PHONY: clean
clean: docs-clean clean-local-tmp clean-docker clean-sipi-tmp ## clean build artifacts
@rm -rf .env
.PHONY: clean-sipi-tmp
clean-sipi-tmp: ## deletes all files in Sipi's tmp folder
@mkdir empty_folder_for_clean_sipi_tmp
@cp sipi/images/tmp/.gitignore empty_folder_for_clean_sipi_tmp/.gitignore
@rsync -a --delete empty_folder_for_clean_sipi_tmp/ sipi/images/tmp/ # use rsync because it can handle large number of files
@rm -r empty_folder_for_clean_sipi_tmp
.PHONY: clean-sipi-projects
clean-sipi-projects: ## deletes all files uploaded within a project
@rm -rf sipi/images/[0-9A-F][0-9A-F][0-9A-F][0-9A-F]
.PHONY: check
check: ## Run code formatting check
@$(SBTX) "check"
.PHONY: fmt
fmt: ## Run code formatting fix
@$(SBTX) "fmt"
.PHONY: help
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
.DEFAULT_GOAL := help