-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
611 lines (559 loc) · 30.9 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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
# Set up makefile config
.RECIPEPREFIX = >
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
# export
# Define globally used variables
# Locations are relative unless indicated otherwise
PACKAGE_NAME := spatialprofilingtoolbox
export PYTHON := python
export BUILD_SCRIPTS_LOCATION_ABSOLUTE := ${PWD}/build/build_scripts
SOURCE_LOCATION := ${PACKAGE_NAME}
PLUGIN_SOURCE_LOCATION := plugin
BUILD_LOCATION := build
BUILD_LOCATION_ABSOLUTE := ${PWD}/build
export TEST_LOCATION := test
export TEST_LOCATION_ABSOLUTE := ${PWD}/${TEST_LOCATION}
LOCAL_USERID := $(shell id -u)
VERSION := $(shell cat version.txt | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
export WHEEL_FILENAME := ${PACKAGE_NAME}-${VERSION}-py3-none-any.whl
export MESSAGE := bash ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/verbose_command_wrapper.sh
help:
>@${MESSAGE} print 'The main targets are:'
>@${MESSAGE} print ' '
>@${MESSAGE} print ' make release-package'
>@${MESSAGE} print ' Build the Python package wheel and push it to PyPI.'
>@${MESSAGE} print ' '
>@${MESSAGE} print ' make build-docker-images'
>@${MESSAGE} print ' Build the Docker images.'
>@${MESSAGE} print ' '
>@${MESSAGE} print ' make build-and-push-docker-images'
>@${MESSAGE} print ' Build the Docker images and push them to DockerHub repositories.'
>@${MESSAGE} print ' '
>@${MESSAGE} print ' make force-rebuild-data-loaded-images'
>@${MESSAGE} print ' Rebuild the data-preloaded Docker images. This is relatively'
>@${MESSAGE} print ' long-running and so is left out of the typical test target'
>@${MESSAGE} print ' fulfillment process.'
>@${MESSAGE} print ' '
>@${MESSAGE} print ' make test'
>@${MESSAGE} print ' Do unit and module tests.'
>@${MESSAGE} print ' '
>@${MESSAGE} print ' make [unit | module]-test-[apiserver | graphs | ondemand | db | workflow]'
>@${MESSAGE} print ' Do only the unit or module tests for the indicated module.'
>@${MESSAGE} print ' '
>@${MESSAGE} print ' make clean'
>@${MESSAGE} print ' Attempt to remove all build or partial-build artifacts.'
>@${MESSAGE} print ' '
>@${MESSAGE} print ' make clean-docker-images'
>@${MESSAGE} print ' Aggressively removes the Docker images created here.'
>@${MESSAGE} print ' It makes use `docker system prune`, which might delete other images, so use at your own risk.'
>@${MESSAGE} print ' This target does not attempt to remove external images pulled as base images, however.'
>@${MESSAGE} print ' Note that normal `make clean` does not attempt to remove Docker images at all.'
>@${MESSAGE} print ' '
>@${MESSAGE} print ' make help'
>@${MESSAGE} print ' Show this text.'
>@${MESSAGE} print ' '
>@${MESSAGE} print 'Use VERBOSE=1 to send command outputs to STDOUT rather than log files.'
>@${MESSAGE} print 'Use NOCACHE=1 to cause docker build commands to rebuild each cached layer.'
>@${MESSAGE} print ' '
# Docker and test variables
export DOCKER_ORG_NAME := nadeemlab
export DOCKER_REPO_PREFIX := spt
export DOCKER_SCAN_SUGGEST:=false
SUBMODULES := apiserver graphs ondemand db workflow
DOCKERIZED_SUBMODULES := apiserver db ondemand
PLUGINS := graph_processing/cg-gnn graph_processing/graph-transformer
CUDA_PLUGINS := graph_processing/cg-gnn
DOCKERFILES := $(foreach submodule,$(DOCKERIZED_SUBMODULES),${BUILD_LOCATION}/$(submodule)/Dockerfile)
DOCKER_BUILD_SUBMODULE_TARGETS := $(foreach submodule,$(DOCKERIZED_SUBMODULES),${BUILD_LOCATION_ABSOLUTE}/$(submodule)/docker.built)
DOCKER_BUILD_PLUGIN_TARGETS := $(foreach plugin,$(PLUGINS),${BUILD_LOCATION_ABSOLUTE}/plugins/$(plugin).docker.built)
DOCKER_BUILD_PLUGIN_CUDA_TARGETS := $(foreach plugin,$(CUDA_PLUGINS),${BUILD_LOCATION_ABSOLUTE}/plugins/$(plugin)-cuda.docker.built)
_UNPUSHABLES := db
PUSHABLE_SUBMODULES := $(filter-out ${_UNPUSHABLES},$(DOCKERIZED_SUBMODULES))
DOCKER_PUSH_SUBMODULE_TARGETS := $(foreach submodule,$(PUSHABLE_SUBMODULES),docker-push-${PACKAGE_NAME}/$(submodule))
DOCKER_PUSH_DEV_SUBMODULE_TARGETS := $(foreach submodule,$(DOCKERIZED_SUBMODULES),docker-push-dev-${PACKAGE_NAME}/$(submodule))
DOCKER_PUSH_PLUGIN_TARGETS := $(foreach plugin,$(PLUGINS),docker-push-${PACKAGE_NAME}/$(plugin))
DOCKER_PUSH_DEV_PLUGIN_TARGETS := $(foreach plugin,$(PLUGINS),docker-push-dev-${PACKAGE_NAME}/$(plugin))
DOCKER_PUSH_PLUGIN_CUDA_TARGETS := $(foreach plugin,$(CUDA_PLUGINS),docker-push-${PACKAGE_NAME}/$(plugin)-cuda)
DOCKER_PUSH_DEV_PLUGIN_CUDA_TARGETS := $(foreach plugin,$(CUDA_PLUGINS),docker-push-dev-${PACKAGE_NAME}/$(plugin)-cuda)
MODULE_TEST_TARGETS := $(foreach submodule,$(SUBMODULES),module-test-$(submodule))
UNIT_TEST_TARGETS := $(foreach submodule,$(SUBMODULES),unit-test-$(submodule))
SINGLETON_TEST_TARGETS := $(foreach submodule,$(SUBMODULES),singleton-test-$(submodule))
DLI := force-rebuild-data-loaded-image
# Define PHONY targets
.PHONY: help release-package check-for-pypi-credentials print-source-files build-and-push-docker-images ${DOCKER_PUSH_SUBMODULE_TARGETS} ${DOCKER_PUSH_PLUGIN_TARGETS} ${DOCKER_PUSH_PLUGIN_CUDA_TARGETS} build-docker-images test module-tests ${MODULE_TEST_TARGETS} ${UNIT_TEST_TARGETS} clean clean-files docker-compositions-rm clean-network-environment generic-spt-push-target data-loaded-images-push-target ensure-plugin-submodules-are-populated
# Submodule-specific variables
export DB_SOURCE_LOCATION_ABSOLUTE := ${PWD}/${SOURCE_LOCATION}/db
export DB_BUILD_LOCATION_ABSOLUTE := ${PWD}/${BUILD_LOCATION}/db
# Locations can't be relative because these are used by the submodules' Makefiles.
# Fetch all runnable files that will be needed for making
PACKAGE_SOURCE_FILES := pyproject.toml $(shell find ${SOURCE_LOCATION} -type f)
# Redefine what shell to pass to submodule makefiles
export SHELL := ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/status_messages_only_shell.sh
# Adjust verbosity based on how make was called
ifdef VERBOSE
export .SHELLFLAGS := -c -super-verbose
else
export .SHELLFLAGS := -c -not-super-verbose
endif
ifdef NOCACHE
export NO_CACHE_FLAG := --no-cache
else
export NO_CACHE_FLAG :=
endif
release-package: development-image check-for-pypi-credentials
>@${MESSAGE} start "Uploading spatialprofilingtoolbox==${VERSION} to PyPI"
>@cp ~/.pypirc .
>@docker run -u ${LOCAL_USERID} --rm --mount type=bind,src=${PWD},dst=/mount_sources -t ${DOCKER_ORG_NAME}-development/${DOCKER_REPO_PREFIX}-development:latest /bin/bash -c 'cd /mount_sources; PYTHONDONTWRITEBYTECODE=1 python -m twine upload --config-file .pypirc --repository ${PACKAGE_NAME} dist/${WHEEL_FILENAME} ' ; echo "$$?" > status_code
>@${MESSAGE} end "Uploaded." "Error."
>@rm -f .pypirc
check-for-pypi-credentials:
>@${MESSAGE} start "Checking for PyPI credentials in ~/.pypirc for spatialprofilingtoolbox"
>@${PYTHON} ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/check_for_credentials.py pypi ; echo "$$?" > status_code
>@${MESSAGE} end "Found." "Not found."
development-image-prerequisites-installed: pyproject.toml.unversioned ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/development_prereqs.Dockerfile
>@${MESSAGE} start "Building development image precursor"
>@cp ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/.dockerignore .
>@docker build \
${NO_CACHE_FLAG} \
--rm \
-f ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/development_prereqs.Dockerfile \
-t ${DOCKER_ORG_NAME}-development/${DOCKER_REPO_PREFIX}-development-prereqs:latest \
. ; echo "$$?" > status_code ; \
status_code=$$(cat status_code); \
if [[ "$$status_code" == "0" ]]; \
then \
touch development-image-prerequisites-installed ; \
fi
>@${MESSAGE} end "Built." "Build failed."
>@rm -f .dockerignore
development-image: ${PACKAGE_SOURCE_FILES} ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/development.Dockerfile development-image-prerequisites-installed
>@${MESSAGE} start "Building development image"
>@cp ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/.dockerignore .
>@docker build \
${NO_CACHE_FLAG} \
--rm \
--no-cache \
--pull=false \
-f ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/development.Dockerfile \
-t ${DOCKER_ORG_NAME}-development/${DOCKER_REPO_PREFIX}-development:latest \
--build-arg WHEEL_FILENAME=$${WHEEL_FILENAME} \
. ; echo "$$?" > status_code ; \
status_code=$$(cat status_code) ; \
if [[ "$$status_code" == "0" ]]; \
then \
if [ ! -d dist/ ]; then mkdir dist ; fi; \
docker run --rm -v $$(pwd)/dist:/buffer ${DOCKER_ORG_NAME}-development/${DOCKER_REPO_PREFIX}-development /bin/sh -c "cp dist/${WHEEL_FILENAME} /buffer; chown ${LOCAL_USERID}:${LOCAL_USERID} /buffer/*; "; \
fi
>@status_code=$$(cat status_code); \
if [[ "$$status_code" == "0" ]]; \
then \
touch development-image ; \
fi
>@${MESSAGE} end "Built." "Build failed."
>@rm -f .dockerignore
pyproject.toml: pyproject.toml.unversioned ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/create_pyproject.py version.txt
>@${MESSAGE} start "Creating pyproject.toml"
>@${PYTHON} ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/create_pyproject.py; echo "$$?" > status_code
>@${MESSAGE} end "Created." "Failed."
print-source-files:
>@echo "${PACKAGE_SOURCE_FILES}" | tr ' ' '\n'
build-and-push-application-images: ${DOCKER_PUSH_SUBMODULE_TARGETS}
build-and-push-docker-images: ${DOCKER_PUSH_SUBMODULE_TARGETS} ${DOCKER_PUSH_PLUGIN_TARGETS} ${DOCKER_PUSH_PLUGIN_CUDA_TARGETS} generic-spt-push-target data-loaded-images-push-target
build-and-push-docker-images-dev: ${DOCKER_PUSH_DEV_SUBMODULE_TARGETS} ${DOCKER_PUSH_DEV_PLUGIN_TARGETS} ${DOCKER_PUSH_DEV_PLUGIN_CUDA_TARGETS}
${DOCKER_PUSH_SUBMODULE_TARGETS}: ${DOCKER_BUILD_SUBMODULE_TARGETS} check-for-docker-credentials
>@submodule_directory=$$(echo $@ | sed 's/^docker-push-//g') ; \
submodule_version=$$(grep '^__version__ = ' $$submodule_directory/__init__.py | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+') ;\
submodule_name=$$(echo $$submodule_directory | sed 's/spatialprofilingtoolbox\///g') ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$submodule_name ; \
${MESSAGE} start "Pushing Docker container $$repository_name"
>@submodule_directory=$$(echo $@ | sed 's/^docker-push-//g') ; \
submodule_version=$$(grep '^__version__ = ' $$submodule_directory/__init__.py | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+') ;\
echo "$$submodule_version"; \
submodule_name=$$(echo $$submodule_directory | sed 's/spatialprofilingtoolbox\///g') ; \
echo "$$submodule_name"; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$submodule_name ; \
echo "$$repository_name"; \
docker push $$repository_name:$$submodule_version ; \
exit_code1=$$?; \
docker push $$repository_name:latest ; \
exit_code2=$$?; \
exit_code=$$(( exit_code1 + exit_code2 )); echo "$$exit_code" > status_code
>@${MESSAGE} end "Pushed." "Not pushed."
${DOCKER_PUSH_DEV_SUBMODULE_TARGETS}: build-docker-images check-for-docker-credentials
>@submodule_directory=$$(echo $@ | sed 's/^docker-push-dev-//g') ; \
submodule_version=$$(grep '^__version__ = ' $$submodule_directory/__init__.py | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+') ;\
submodule_name=$$(echo $$submodule_directory | sed 's/spatialprofilingtoolbox\///g') ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$submodule_name ; \
${MESSAGE} start "Pushing Docker container $$repository_name"
>@submodule_directory=$$(echo $@ | sed 's/^docker-push-dev-//g') ; \
submodule_version=$$(grep '^__version__ = ' $$submodule_directory/__init__.py | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+') ;\
echo "$$submodule_version"; \
submodule_name=$$(echo $$submodule_directory | sed 's/spatialprofilingtoolbox\///g') ; \
echo "$$submodule_name"; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$submodule_name ; \
echo "$$repository_name"; \
docker push $$repository_name:dev ; \
exit_code1=$$?; \
echo "$$exit_code1" > status_code
>@${MESSAGE} end "Pushed." "Not pushed."
${DOCKER_PUSH_PLUGIN_TARGETS}: build-docker-images check-for-docker-credentials
>@plugin_name=$$(basename $@) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
${MESSAGE} start "Pushing Docker container $$repository_name"
>@plugin_name=$$(basename $@) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
plugin_relative_directory=$$(dirname $@ | sed 's,docker-push-${PACKAGE_NAME}\/,,g')/$$plugin_name ; \
source_directory=${PLUGIN_SOURCE_LOCATION}/$$plugin_relative_directory ; \
plugin_version=$$(cat $$source_directory/version.txt) ; \
echo "$$plugin_version"; \
echo "$$plugin_name"; \
echo "$$repository_name"; \
docker push $$repository_name:$$plugin_version ; \
exit_code1=$$?; \
docker push $$repository_name:latest ; \
exit_code2=$$?; \
exit_code=$$(( exit_code1 + exit_code2 )); echo "$$exit_code" > status_code
>@${MESSAGE} end "Pushed." "Not pushed."
${DOCKER_PUSH_DEV_PLUGIN_TARGETS}: build-docker-images check-for-docker-credentials
>@plugin_name=$$(basename $@) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
${MESSAGE} start "Pushing Docker container $$repository_name"
>@plugin_name=$$(basename $@) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
plugin_relative_directory=$$(dirname $@ | sed 's,docker-push-dev-${PACKAGE_NAME}\/,,g')/$$plugin_name ; \
source_directory=${PLUGIN_SOURCE_LOCATION}/$$plugin_relative_directory ; \
plugin_version=$$(cat $$source_directory/version.txt) ; \
echo "$$plugin_version"; \
echo "$$plugin_name"; \
echo "$$repository_name"; \
docker push $$repository_name:dev ; \
exit_code1=$$?; \
echo "$$exit_code1" > status_code
>@${MESSAGE} end "Pushed." "Not pushed."
${DOCKER_PUSH_PLUGIN_CUDA_TARGETS}: build-docker-images check-for-docker-credentials
>@plugin_name=$$(basename $@ -cuda) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
${MESSAGE} start "Pushing Docker container $$repository_name:cuda"
>@plugin_name=$$(basename $@ -cuda) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
plugin_relative_directory=$$(dirname $@ | sed 's,docker-push-${PACKAGE_NAME}\/,,g')/$$plugin_name ; \
source_directory=${PLUGIN_SOURCE_LOCATION}/$$plugin_relative_directory ; \
plugin_version=$$(cat $$source_directory/version.txt) ; \
echo "$$plugin_version"; \
echo "$$plugin_name"; \
echo "$$repository_name"; \
docker push $$repository_name:cuda-$$plugin_version ; \
exit_code1=$$?; \
docker push $$repository_name:cuda-latest ; \
exit_code2=$$?; \
exit_code=$$(( exit_code1 + exit_code2 )); echo "$$exit_code" > status_code
>@${MESSAGE} end "Pushed." "Not pushed."
${DOCKER_PUSH_DEV_PLUGIN_CUDA_TARGETS}: build-docker-images check-for-docker-credentials
>@plugin_name=$$(basename $@ -cuda) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
${MESSAGE} start "Pushing Docker container $$repository_name:cuda"
>@plugin_name=$$(basename $@ -cuda) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
plugin_relative_directory=$$(dirname $@ | sed 's,docker-push-dev-${PACKAGE_NAME}\/,,g')/$$plugin_name ; \
source_directory=${PLUGIN_SOURCE_LOCATION}/$$plugin_relative_directory ; \
plugin_version=$$(cat $$source_directory/version.txt) ; \
echo "$$plugin_version"; \
echo "$$plugin_name"; \
echo "$$repository_name"; \
docker push $$repository_name:cuda-dev ; \
exit_code1=$$?; \
echo "$$exit_code1" > status_code
>@${MESSAGE} end "Pushed." "Not pushed."
generic-spt-push-target: build-docker-images check-for-docker-credentials
>@repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX} ; \
${MESSAGE} start "Pushing Docker container $$repository_name"
>@repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX} ; \
docker tag ${DOCKER_ORG_NAME}-development/${DOCKER_REPO_PREFIX}-development:latest $$repository_name:${VERSION} ; \
docker push $$repository_name:${VERSION} ; \
exit_code1=$$?; \
docker tag ${DOCKER_ORG_NAME}-development/${DOCKER_REPO_PREFIX}-development:latest $$repository_name:latest ; \
docker push $$repository_name:latest ; \
exit_code2=$$?; \
exit_code=$$(( exit_code1 + exit_code2 )); echo "$$exit_code" > status_code
>@${MESSAGE} end "Pushed." "Not pushed."
data-loaded-images-push-target:
>@${MESSAGE} start "Pushing preloaded data Docker containers"
>@repository_name_prefix=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-db-preloaded ; \
codes=0 ; \
for suffix in 1 2 1and2 1small 1smallnointensity; \
do \
existing=$$repository_name_prefix-$$suffix:latest ; \
tag=$$repository_name_prefix-$$suffix:${VERSION} ; \
docker tag $$existing $$tag ; \
docker push $$existing ; \
exitcode="$$?" ; \
codes=$$(( codes + exitcode )) ; \
docker push $$tag ; \
exitcode="$$?" ; \
codes=$$(( codes + exitcode )) ; \
done; \
echo "$$codes" > status_code
>@${MESSAGE} end "Pushed." "Not pushed."
check-for-docker-credentials:
>@${MESSAGE} start "Checking for Docker credentials in ~/.docker/config.json"
>@${PYTHON} ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/check_for_credentials.py docker ; status="$$?"; echo "$$status" > status_code; if [[ "$$status" == "0" ]]; then touch check-for-docker-credentials; fi;
>@${MESSAGE} end "Found." "Not found."
check-dockerfiles-consistency:
>@${MESSAGE} start "Checking dependency lists in Dockerfiles."
>@${PYTHON} ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/check_dockerfiles_consistency.py ${DOCKERIZED_SUBMODULES}; echo "$$?" > status_code;
>@status_code=$$(cat status_code); if [[ "$$status_code" == "0" && ( ! -f check-dockerfiles-consistency ) ]]; then touch check-dockerfiles-consistency; fi;
>@${MESSAGE} end "Consistent." "Something missing."
ensure-plugin-submodules-are-populated:
>@git submodule update --init --recursive
build-application-images: ${DOCKER_BUILD_SUBMODULE_TARGETS}
build-docker-images: ${DOCKER_BUILD_SUBMODULE_TARGETS} ${DOCKER_BUILD_PLUGIN_TARGETS} ${DOCKER_BUILD_PLUGIN_CUDA_TARGETS}
# Build the Docker container for each submodule by doing the following:
# 1. Identify the submodule being built
# 2. Emit a message about it
# 3. Copy relevant files to the build folder
# 4. docker build the container
# 5. Remove copied files
${DOCKER_BUILD_SUBMODULE_TARGETS}: ${DOCKERFILES} development-image check-docker-daemon-running check-for-docker-credentials check-dockerfiles-consistency
>@submodule_directory=$$(echo $@ | sed 's/\/docker.built//g') ; \
dockerfile=$${submodule_directory}/Dockerfile ; \
submodule_name=$$(echo $$submodule_directory | sed 's,${BUILD_LOCATION_ABSOLUTE}\/,,g') ; \
submodule_version=$$(grep '^__version__ = ' ${SOURCE_LOCATION}/$$submodule_name/__init__.py | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+') ;\
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$submodule_name ; \
${MESSAGE} start "Building Docker image $$repository_name"
>@submodule_directory=$$(echo $@ | sed 's/\/docker.built//g') ; \
dockerfile=$${submodule_directory}/Dockerfile ; \
submodule_name=$$(echo $$submodule_directory | sed 's,${BUILD_LOCATION_ABSOLUTE}\/,,g') ; \
submodule_version=$$(grep '^__version__ = ' ${SOURCE_LOCATION}/$$submodule_name/__init__.py | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+') ;\
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$submodule_name ; \
cp dist/${WHEEL_FILENAME} $$submodule_directory ; \
cp $$submodule_directory/Dockerfile ./Dockerfile ; \
cp ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/.dockerignore . ; \
docker build \
${NO_CACHE_FLAG} \
-f ./Dockerfile \
-t ${DOCKER_REPO_PREFIX}-$$submodule_name \
-t $$repository_name:$$submodule_version \
-t $$repository_name:latest \
-t $$repository_name:dev \
--build-arg version=$$submodule_version \
--build-arg service_name=$$submodule_name \
--build-arg WHEEL_FILENAME=$${WHEEL_FILENAME} \
$$submodule_directory ; echo "$$?" > status_code; \
if [[ "$$(cat status_code)" == "0" ]]; \
then \
touch $@ ;\
fi
>@${MESSAGE} end "Built." "Build failed."
>@submodule_directory=$$(echo $@ | sed 's/\/docker.built//g') ; \
rm $$submodule_directory/${WHEEL_FILENAME} ; \
rm ./Dockerfile ; \
rm ./.dockerignore ; \
${DOCKER_BUILD_PLUGIN_TARGETS}: check-docker-daemon-running check-for-docker-credentials check-dockerfiles-consistency ensure-plugin-submodules-are-populated
>@plugin_name=$$(basename $@ .docker.built) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
${MESSAGE} start "Building Docker image $$repository_name"
>@plugin_name=$$(basename $@ .docker.built) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
plugin_relative_directory=$$(dirname $@ | sed 's,${BUILD_LOCATION_ABSOLUTE}\/plugins\/,,g')/$$plugin_name ; \
source_directory=${PLUGIN_SOURCE_LOCATION}/$$plugin_relative_directory ; \
plugin_version=$$(cat $$source_directory/version.txt) ; \
plugin_directory=$$(dirname $@)/$$plugin_name ; \
mkdir -p $$plugin_directory ; \
cp -r $$source_directory/* $$plugin_directory ; \
cp $$(dirname $@)/$$(basename $@ .docker.built).dockerfile ./Dockerfile ; \
cp ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/.dockerignore . ; \
docker build \
${NO_CACHE_FLAG} \
-f ./Dockerfile \
-t $$repository_name:$$plugin_version \
-t $$repository_name:latest \
-t $$repository_name:dev \
--build-arg version=$$plugin_version \
--build-arg service_name=$$plugin_name \
$$plugin_directory ; echo "$$?" > status_code; \
if [[ "$$(cat status_code)" == "0" ]]; \
then \
touch $@ ; \
fi
>@${MESSAGE} end "Built." "Build failed."
>@plugin_name=$$(basename $@ .docker.built) ; \
plugin_directory=$$(dirname $@)/$$plugin_name ; \
rm -r $$plugin_directory ; \
${DOCKER_BUILD_PLUGIN_CUDA_TARGETS}: check-docker-daemon-running check-for-docker-credentials check-dockerfiles-consistency ensure-plugin-submodules-are-populated
>@plugin_name=$$(basename $@ -cuda.docker.built) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
${MESSAGE} start "Building Docker image $$repository_name:cuda"
>@plugin_name=$$(basename $@ -cuda.docker.built) ; \
repository_name=${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-$$plugin_name ; \
plugin_relative_directory=$$(dirname $@ | sed 's,${BUILD_LOCATION_ABSOLUTE}\/plugins\/,,g')/$$plugin_name ; \
source_directory=${PLUGIN_SOURCE_LOCATION}/$$plugin_relative_directory ; \
plugin_version=$$(cat $$source_directory/version.txt) ; \
plugin_directory=$$(dirname $@)/$$plugin_name-cuda ; \
mkdir -p $$plugin_directory ; \
cp $$source_directory/* $$plugin_directory ; \
cp $$(dirname $@)/$$(basename $@ .docker.built).dockerfile ./Dockerfile ; \
cp ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/.dockerignore . ; \
docker build \
${NO_CACHE_FLAG} \
-f ./Dockerfile \
-t $$repository_name:cuda-$$plugin_version \
-t $$repository_name:cuda-latest \
-t $$repository_name:cuda-dev \
--build-arg version=$$plugin_version \
--build-arg service_name=$$plugin_name \
$$plugin_directory ; echo "$$?" > status_code; \
if [[ "$$(cat status_code)" == "0" ]]; \
then \
touch $@ ; \
fi
>@${MESSAGE} end "Built." "Build failed."
>@plugin_name=$$(basename $@ -cuda.docker.built) ; \
plugin_directory=$$(dirname $@)/$$plugin_name-cuda ; \
rm -r $$plugin_directory ; \
check-docker-daemon-running:
>@${MESSAGE} start "Checking that Docker daemon is running"
>@docker stats --no-stream ; echo "$$?" > status_code
>@${MESSAGE} end "Running." "Not running."
>@status_code=$$(cat status_code); \
if [ $$status_code -gt 0 ] ; \
then \
${MESSAGE} start "Attempting to start Docker daemon" ; \
bash ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/start_docker_daemon.sh ; echo "$$?" > status_code ; \
status_code=$$(cat status_code); \
if [ $$status_code -eq 1 ] ; \
then \
${MESSAGE} end "--" "Timed out." ; \
else \
${MESSAGE} end "Started." "Failed to start." ; \
fi ; \
fi ; \
touch check-docker-daemon-running
.initial_time.txt:
>@date +%s > .initial_time.txt
test: unit-tests module-tests
>@${MESSAGE} start " "
>@cp .initial_time.txt .current_time.txt; \
rm .initial_time.txt; \
${MESSAGE} end "Total time:" "Error computing time."
module-tests: ${MODULE_TEST_TARGETS}
${MODULE_TEST_TARGETS}: development-image data-loaded-image-1smallnointensity data-loaded-image-1small data-loaded-image-1 data-loaded-image-1and2 ${DOCKER_BUILD_SUBMODULE_TARGETS} clean-network-environment .initial_time.txt
>@submodule_directory=$$(echo $@ | sed 's/^module-test-/${BUILD_LOCATION}\//g') ; \
${MAKE} SHELL=$(SHELL) --no-print-directory -C $$submodule_directory module-tests ;
unit-tests: ${UNIT_TEST_TARGETS}
${UNIT_TEST_TARGETS}: development-image data-loaded-image-1smallnointensity data-loaded-image-1small data-loaded-image-1 data-loaded-image-1and2 ${DOCKER_BUILD_SUBMODULE_TARGETS} clean-network-environment .initial_time.txt
>@submodule_directory=$$(echo $@ | sed 's/^unit-test-/${BUILD_LOCATION}\//g') ; \
${MAKE} SHELL=$(SHELL) --no-print-directory -C $$submodule_directory unit-tests ;
${SINGLETON_TEST_TARGETS}: development-image data-loaded-image-1small data-loaded-image-1 data-loaded-image-1and2 ${DOCKER_BUILD_SUBMODULE_TARGETS} clean-network-environment .initial_time.txt
>@submodule_directory=$$(echo $@ | sed 's/^singleton-test-/${BUILD_LOCATION}\//g') ; \
${MAKE} SHELL=$(SHELL) --no-print-directory -C $$submodule_directory singleton-tests ;
# The below explicitly checks whether the docker image already exists locally.
# If so, not rebuilt. To trigger rebuild, use "make clean-docker-images" first,
# or directly force-rebuild-data-loaded-images .
data-loaded-image-%: ${BUILD_LOCATION_ABSOLUTE}/db/docker.built ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/import_test_dataset%.sh development-image
>@${MESSAGE} start "Building test-data-loaded spt-db image ($*)"
>@cp ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/.dockerignore .
>@source ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/check_image_exists.sh; \
exists=$$(check_image_exists ${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-db-preloaded-$*); \
if [[ "$$exists" == "no" ]]; \
then \
docker container create --name temporary-spt-db-preloading --network host -e POSTGRES_PASSWORD=postgres -e PGDATA=.postgres/pgdata ${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-db:latest ; \
docker container start temporary-spt-db-preloading && \
bash ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/poll_container_readiness_direct.sh temporary-spt-db-preloading && \
pipeline_cmd="cd /working_dir; cp -r /mount_sources/build .; cp -r /mount_sources/test .; bash build/build_scripts/import_test_dataset$*.sh "; \
docker container run \
-i \
--rm \
--network container:temporary-spt-db-preloading \
--mount type=bind,src=${PWD},dst=/mount_sources \
--mount type=tmpfs,destination=/working_dir \
-t ${DOCKER_ORG_NAME}-development/${DOCKER_REPO_PREFIX}-development:latest \
/bin/bash -c \
"$$pipeline_cmd" ; echo "$$?" > status_code && \
docker commit temporary-spt-db-preloading ${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-db-preloaded-$*:latest && \
docker container rm --force temporary-spt-db-preloading ; \
fi
>@status_code=$$(cat status_code); \
if [[ "$$status_code" == "0" ]]; \
then \
touch data-loaded-image-$* ; \
fi
>@${MESSAGE} end "Built." "Build failed."
>@rm -f .dockerignore
force-rebuild-data-loaded-images: ${DLI}-1 ${DLI}-2 ${DLI}-1and2 ${DLI}-1small ${DLI}-1smallnointensity
force-rebuild-data-loaded-image-%: ${BUILD_LOCATION_ABSOLUTE}/db/docker.built ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/import_test_dataset%.sh
>@${MESSAGE} start "Rebuilding test-data-loaded spt-db image ($*)"
>@cp ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/.dockerignore .
>@source ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/check_image_exists.sh; \
docker container create --name temporary-spt-db-preloading --network host -e POSTGRES_PASSWORD=postgres -e PGDATA=.postgres/pgdata ${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-db:latest ; \
docker container start temporary-spt-db-preloading && \
bash ${BUILD_SCRIPTS_LOCATION_ABSOLUTE}/poll_container_readiness_direct.sh temporary-spt-db-preloading && \
pipeline_cmd="cd /working_dir; cp -r /mount_sources/build .; cp -r /mount_sources/test .; bash build/build_scripts/import_test_dataset$*.sh "; \
docker run \
--rm \
--network container:temporary-spt-db-preloading \
--mount type=bind,src=${PWD},dst=/mount_sources \
--mount type=tmpfs,destination=/working_dir \
-t ${DOCKER_ORG_NAME}-development/${DOCKER_REPO_PREFIX}-development:latest \
/bin/bash -c \
"$$pipeline_cmd" ; echo "$$?" > status_code && \
docker commit temporary-spt-db-preloading ${DOCKER_ORG_NAME}/${DOCKER_REPO_PREFIX}-db-preloaded-$*:latest && \
docker container rm --force temporary-spt-db-preloading ;
>@status_code=$$(cat status_code); \
if [[ "$$status_code" == "0" ]]; \
then \
touch data-loaded-image-$* ; \
fi
>@${MESSAGE} end "Rebuilt." "Rebuild failed."
>@rm -f .dockerignore
clean: clean-files clean-network-environment
clean-files:
>@rm -rf ${PACKAGE_NAME}.egg-info/
>@rm -rf dist/
>@rm -f .initiation_message_size
>@rm -f .current_time.txt
>@rm -f .initial_time.txt
>@rm -f ${BUILD_LOCATION}/*/.initiation_message_size
>@rm -f ${BUILD_LOCATION}/*/.current_time.txt
>@for submodule in ${SUBMODULES} ; do \
submodule_directory=${BUILD_LOCATION}/$$submodule ; \
${MAKE} SHELL=$(SHELL) --no-print-directory -C $$submodule_directory clean ; \
rm -rf $$submodule_directory/docker.built ; \
done
>@rm -f Dockerfile
>@rm -f .dockerignore
>@rm -rf spatialprofilingtoolbox.egg-info/
>@rm -rf __pycache__/
>@rm -f development-image
>@rm -f development-image-prerequisites-installed
>@rm -f pyproject.toml
>@rm -f data-loaded-image-1
>@rm -f data-loaded-image-2
>@rm -f data-loaded-image-1and2
>@rm -f data-loaded-image-1small
>@rm -f data-loaded-image-1smallnointensity
>@rm -f file_manifest.tsv.bak
>@rm -f .nextflow.log; rm -f .nextflow.log.*; rm -rf .nextflow/; rm -f configure.sh; rm -f run.sh; rm -f main.nf; rm -f nextflow.config; rm -rf work/; rm -rf results/
>@rm -f status_code
>@rm -f check-docker-daemon-running
>@rm -f check-dockerfiles-consistency
>@rm -f check-for-docker-credentials
>@rm -rf ${BUILD_LOCATION}/lib
>@rm -f build/*/log_of_build.log
>@rm -f log_of_build.log
docker-compositions-rm: check-docker-daemon-running
>@${MESSAGE} start "Running docker compose rm (remove)"
>@docker compose --project-directory ./build/apiserver/ rm --force --stop ; status_code1="$$?" ; \
docker compose --project-directory ./build/ondemand/ rm --force --stop ; status_code2="$$?" ; \
docker compose --project-directory ./build/db/ rm --force --stop ; status_code3="$$?" ; \
status_code=$$(( status_code1 + status_code2 + status_code3 + status_code4 + status_code5 )) ; echo $$status_code > status_code
>@docker container rm --force temporary-spt-db-preloading
>@${MESSAGE} end "Down." "Error."
clean-network-environment: docker-compositions-rm
clean-docker-images:
>@docker system prune -f
>@for tag in $$(docker image ls | grep ${DOCKER_ORG_NAME} | awk '{print $$1":"$$2}'); \
do \
docker image rm $$tag; \
done;
>@docker system prune -f