-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
228 lines (184 loc) · 8.66 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
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
setup: | install build-volumes start-traefik start-services
@ echo "$(MSG_PRINT)Docker-based services started; make stop to stop"
setup-dev: | install-dev build-volumes start-traefik start-services
@ echo "$(MSG_PRINT)Docker-based services started; make stop to stop"
start: | build-volumes 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
#-----------------------------------------------------------------------------
# Fuseki control for github actions
#-----------------------------------------------------------------------------
setup-docker-fuseki: | build-volumes
@ echo -e '$(BUILD_PRINT)Building the Fuseki service'
@ docker-compose --file docker/docker-compose-tests.yml --env-file docker/.env build rdf-differ-fuseki
run-docker-fuseki:
@ echo -e '$(BUILD_PRINT)Starting the Fuseki service'
@ docker-compose --file docker/docker-compose-tests.yml --env-file docker/.env up -d rdf-differ-fuseki
#-----------------------------------------------------------------------------
# Test commands
#-----------------------------------------------------------------------------
test-data-fuseki: | setup-docker-fuseki run-docker-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:
@ echo -e '$(BUILD_PRINT)Starting redis'
@ docker-compose --file docker/docker-compose-tests.yml --env-file docker/.env up -d rdf-differ-redis
run-docker-api:
@ echo -e '$(BUILD_PRINT)Starting api'
@ docker-compose --file docker/docker-compose-tests.yml --env-file docker/.env up -d rdf-differ-api
run-docker-ui:
@ echo -e '$(BUILD_PRINT)Starting ui'
@ docker-compose --file docker/docker-compose-tests.yml --env-file docker/.env up -d rdf-differ-ui
test: | install-python-dependencies-dev test-data-fuseki run-docker-redis run-docker-api
@ echo "$(BUILD_PRINT)Running the 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
#-----------------------------------------------------------------------------
# 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|' $@