-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
290 lines (240 loc) · 11.6 KB
/
Makefile
File metadata and controls
290 lines (240 loc) · 11.6 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
include docker/.env
BUILD_PRINT = \e[1;34mSTEP: \e[0m
MSG_PRINT = \e[1;34mINFO: \e[0m
WARN_PRINT = \e[1;34mWARNING: \e[0m
DEB_OS=$(shell command -v apt > /dev/null && echo 1)
RPM_OS=$(shell command -v yum > /dev/null && echo 1)
OS_DOCKER=$(shell command -v docker > /dev/null && echo 1)
OS_DOCKERC=$(shell command -v docker compose > /dev/null && echo 1)
#-----------------------------------------------------------------------------
# Install dev environment
#-----------------------------------------------------------------------------
# how to set envs to local
# set -o allexport; source docker/.env; set +o allexport
start: | start-traefik start-services
@ echo "$(MSG_PRINT)Docker-based services started; make stop to stop"
stop: | stop-traefik stop-services
@ echo "$(MSG_PRINT)Docker-based services stopped; make start to restart"
install: | install-os-dependencies install-python-dependencies
@ echo "$(MSG_PRINT)To get started quickly with docker, make start"
@ echo "$(MSG_PRINT)To run tests, make install-python-dependencies-dev"
install-dev: | install-os-dependencies install-python-dependencies-dev
@ echo "$(MSG_PRINT)To get started quickly with docker, make start"
install-os-dependencies:
ifeq ($(DEB_OS), 1)
@ sudo apt install redis-server default-jre
else ifeq ($(RPM_OS), 1)
@ sudo yum install redis java-11-openjdk
else
@ echo "$(MSG_PRINT)Operating system not supported"
@ echo "$(MSG_PRINT)Install Java 11+ and Redis 6+"
@ echo "$(MSG_PRINT)Then make install-python-dependencies"
false
endif
install-python-dependencies:
@ echo "$(BUILD_PRINT)Installing the production requirements"
@ python -m pip install --upgrade pip
@ python -m pip install -r requirements/prod.txt
install-python-dependencies-dev:
@ echo "$(BUILD_PRINT)Installing the development requirements"
@ python -m pip install --upgrade pip
@ python -m pip install -r requirements/dev.txt
setup-local-fuseki:
@ ./bash/setup_fuseki.sh
run-local-fuseki:
@ ./fuseki/fuseki-server -q
run-local-api:
@ ./bash/run_api.sh
run-local-ui:
@ ./bash/run_ui.sh
run-system-redis:
ifeq ($(DEB_OS), 1)
# running as root, and replacing a system config, are both bad practices!
@ echo "$(WARN_PRINT)Backing up and replacing a system config as root!"
@ sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.rdf_differ.bak -v
@ sudo cp docker/redis.conf /etc/redis/redis.conf -v
@ sudo systemctl restart redis.service
else ifeq ($(RPM_OS), 1)
@ sudo systemctl enable redis --now
else
@ echo "$(MSG_PRINT)Operating system not supported"
@ echo "$(MSG_PRINT)Please start the Redis server yourself"
@ echo "$(MSG_PRINT)Refer also to docker/redis.conf"
false
endif
stop-local-applications:
@ ./bash/stop_gunicorn.sh
#-----------------------------------------------------------------------------
# Service commands
#-----------------------------------------------------------------------------
build-volumes:
ifeq ($(OS_DOCKER), 1)
@ echo -e '$(BUILD_PRINT)Creating a shared volume for micro-services'
@ docker volume create rdf-differ-template-${ENVIRONMENT}
@ docker volume create rdf-differ-template
else
@ echo "$(MSG_PRINT)Docker not found"
@ echo "$(MSG_PRINT)Please see README for other ways of starting up"
false
endif
build-services:
ifeq ($(OS_DOCKERC), 1)
@ echo -e '$(BUILD_PRINT)Building the RDF Differ micro-services'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose.yml --env-file docker/.env build
else
@ echo "$(MSG_PRINT)Docker not found, please see README"
false
endif
build-externals:
@ echo -e "$(BUILD_PRINT)Creating the necessary volumes, networks and folders and setting the special rights"
@ docker network create proxy-net || true
start-traefik: build-externals
@ echo -e "$(BUILD_PRINT)Starting the Traefik services $(END_BUILD_PRINT)"
@ docker compose -p common --file ./docker/traefik/docker-compose.yml --env-file docker/.env up -d
stop-traefik:
@ echo -e "$(BUILD_PRINT)Stopping the Traefik services $(END_BUILD_PRINT)"
@ docker compose -p common --file ./docker/traefik/docker-compose.yml --env-file docker/.env down
start-services: build-volumes
ifeq ($(OS_DOCKERC), 1)
@ echo -e '$(BUILD_PRINT)Starting the RDF Differ micro-services'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose.yml --env-file docker/.env up -d
else
@ echo "$(MSG_PRINT)Docker not found, please see README"
false
endif
stop-services:
ifeq ($(OS_DOCKERC), 1)
@ echo -e '$(BUILD_PRINT)Stopping the RDF Differ micro-services'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose.yml --env-file docker/.env stop
else
@ echo "$(MSG_PRINT)Docker not found, please see README"
false
endif
teardown-services:
ifeq ($(OS_DOCKERC), 1)
@ echo -e '$(BUILD_PRINT)Tearing down the microservice environment'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose.yml --env-file docker/.env down --volumes --remove-orphans
else
@ echo "$(MSG_PRINT)Docker not found, please see README"
false
endif
#-----------------------------------------------------------------------------
# Fuseki control for github actions
#-----------------------------------------------------------------------------
build-docker-fuseki-test: | build-volumes
@ echo -e '$(BUILD_PRINT)Building the Fuseki service'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose-tests.yml --env-file docker/.env build rdf-differ-fuseki
run-docker-fuseki-test: | build-docker-fuseki-test
@ echo -e '$(BUILD_PRINT)Starting the Fuseki service'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose-tests.yml --env-file docker/.env up -d rdf-differ-fuseki
#-----------------------------------------------------------------------------
# Test commands
#-----------------------------------------------------------------------------
test-data-fuseki:
@ echo "$(BUILD_PRINT)Building dummy "subdiv" and "abc" test datasets at http://localhost:$(if $(RDF_DIFFER_FUSEKI_PORT),$(RDF_DIFFER_FUSEKI_PORT),unknown port)/$$/datasets"
@ sleep 5
@ curl --anyauth --user 'admin:admin' -d 'dbType=mem&dbName=subdiv' 'http://localhost:$(RDF_DIFFER_FUSEKI_PORT)/$$/datasets'
@ curl --anyauth --user 'admin:admin' -d 'dbType=mem&dbName=abc' 'http://localhost:$(RDF_DIFFER_FUSEKI_PORT)/$$/datasets'
run-docker-redis-test:
@ echo -e '$(BUILD_PRINT)Starting redis'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose-tests.yml --env-file docker/.env up -d rdf-differ-redis
run-docker-api-test:
@ echo -e '$(BUILD_PRINT)Starting api'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose-tests.yml --env-file docker/.env up -d rdf-differ-api
run-docker-ui-test:
@ echo -e '$(BUILD_PRINT)Starting ui'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose-tests.yml --env-file docker/.env up -d rdf-differ-ui
run-docker-celery-test:
@ echo -e '$(BUILD_PRINT)Starting celery worker'
@ docker compose -p rdf-differ-${ENVIRONMENT} --file docker/docker-compose-tests.yml --env-file docker/.env up -d rdf-differ-celery-worker
# it is advisable to run this separately before and not as a dependency of the test to ensure no race condition occurs (tests starting before services are ready)
start-services-test: | run-docker-fuseki-test run-docker-redis-test run-docker-celery-test run-docker-api-test
@ echo "$(BUILD_PRINT)All docker services for testing started; waiting 5s for them to stabilize"
@ sleep 5
test: | install-python-dependencies-dev test-data-fuseki
@ echo "$(BUILD_PRINT)Running tests using Docker services"
@ pytest
lint:
@ echo "$(BUILD_PRINT)Linting the code"
@ flake8 || true
#-----------------------------------------------------------------------------
# Template commands
#-----------------------------------------------------------------------------
set-report-template:
@ echo "$(BUILD_PRINT)Copying custom template"
@ docker rm temp | true
@ docker volume rm rdf-differ-template | true
@ docker volume create rdf-differ-template
@ docker container create --name temp -v rdf-differ-template:/data busybox
@ docker cp $(location). temp:/data
@ docker rm temp
#-----------------------------------------------------------------------------
# Template update commands
#-----------------------------------------------------------------------------
# Default values for environment variables
TEMPLATE_SRC_DIR ?= ../diff-query-generator
TEMPLATE_OUTPUT_DIR ?= $(TEMPLATE_SRC_DIR)/output
DEFAULT_PROFILE ?= owl-core
DEFAULT_TEMPLATE ?= html
PREFERRED_PROFILES ?= owl-core shacl-core skos-core
PREFERRED_TEMPLATES ?= html asciidoc
# Derived paths
TEMPLATE_SRC_BASE = $(TEMPLATE_OUTPUT_DIR)/$(DEFAULT_PROFILE)
TEMPLATE_QUERIES_SRC = $(TEMPLATE_SRC_BASE)/queries
TEMPLATE_HTML_SRC = $(TEMPLATE_SRC_BASE)/$(DEFAULT_TEMPLATE)
TEMPLATE_DEST_BASE = resources/templates/$(DEFAULT_PROFILE)-en-only
TEMPLATE_QUERIES_DEST = $(TEMPLATE_DEST_BASE)/queries
TEMPLATE_HTML_DEST = $(TEMPLATE_DEST_BASE)/template_variants/$(DEFAULT_TEMPLATE)/templates
update_template:
@ echo "$(BUILD_PRINT)Updating templates from $(TEMPLATE_SRC_BASE)"
@ mkdir -p $(TEMPLATE_QUERIES_DEST)
@ mkdir -p $(TEMPLATE_HTML_DEST)
@ echo "$(MSG_PRINT)Copying queries from $(TEMPLATE_QUERIES_SRC) to $(TEMPLATE_QUERIES_DEST)"
@ cp -r $(TEMPLATE_QUERIES_SRC)/* $(TEMPLATE_QUERIES_DEST)/
@ echo "$(MSG_PRINT)Copying $(DEFAULT_TEMPLATE) templates from $(TEMPLATE_HTML_SRC) to $(TEMPLATE_HTML_DEST)"
@ cp -r $(TEMPLATE_HTML_SRC)/* $(TEMPLATE_HTML_DEST)/
@ echo "$(MSG_PRINT)Template update completed"
update_all_templates:
@ for profile in $(PREFERRED_PROFILES); do \
for type in $(PREFERRED_TEMPLATES); do \
echo "$(BUILD_PRINT)Updating $$type templates for $$profile"; \
src_base=$(TEMPLATE_OUTPUT_DIR)/$$profile; \
queries_src=$$src_base/queries; \
type_src=$$src_base/$$type; \
dest_base=resources/templates/$$profile-en-only; \
queries_dest=$$dest_base/queries; \
type_dest=$$dest_base/template_variants/$$type/templates; \
mkdir -p $$queries_dest; \
mkdir -p $$type_dest; \
echo "$(MSG_PRINT)Copying queries from $$queries_src to $$queries_dest"; \
cp -r $$queries_src/* $$queries_dest/; \
echo "$(MSG_PRINT)Copying $$type templates from $$type_src to $$type_dest"; \
cp -r $$type_src/* $$type_dest/; \
echo "$(MSG_PRINT)Template update for $$profile ($$type) completed"; \
done \
done
#-----------------------------------------------------------------------------
# Run UI dev environment
#-----------------------------------------------------------------------------
run-dev-ui:
@ export FLASK_APP=rdf_differ.entrypoints.ui.run
@ export FLASK_ENV=development
@ flask run
#-----------------------------------------------------------------------------
# Gherkin feature and acceptance test generation commands
#-----------------------------------------------------------------------------
FEATURES_FOLDER = tests/features
STEPS_FOLDER = tests/steps
FEATURE_FILES := $(wildcard $(FEATURES_FOLDER)/*.feature)
EXISTENT_TEST_FILES = $(wildcard $(STEPS_FOLDER)/*.py)
HYPOTHETICAL_TEST_FILES := $(addprefix $(STEPS_FOLDER)/test_, $(notdir $(FEATURE_FILES:.feature=.py)))
TEST_FILES := $(filter-out $(EXISTENT_TEST_FILES),$(HYPOTHETICAL_TEST_FILES))
generate-tests-from-features: $(TEST_FILES)
@ echo "$(BUILD_PRINT)The following test files should be generated: $(TEST_FILES)"
@ echo "$(BUILD_PRINT)Done generating missing feature files"
@ echo "$(BUILD_PRINT)Verifying if there are any missing step implementations"
@ py.test --generate-missing --feature $(FEATURES_FOLDER)
$(addprefix $(STEPS_FOLDER)/test_, $(notdir $(STEPS_FOLDER)/%.py)): $(FEATURES_FOLDER)/%.feature
@ echo "$(BUILD_PRINT)Generating the testfile "$@" from "$<" feature file"
@ pytest-bdd generate $< > $@
@ sed -i 's|features|../features|' $@