-
Notifications
You must be signed in to change notification settings - Fork 50
/
Makefile
71 lines (59 loc) · 2.12 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
#
# Parameters
#
# Name of the docker executable
DOCKER = docker
# DockerHub organization and repository to pull/push the images from/to
ORG = slicer
REPO = slicerexecutionmodel
DIRECTORIES = \
Docker-ITK-master_USE_SYSTEM_LIBRARIES-OFF
# On CircleCI, do not attempt to delete container
# See https://circleci.com/docs/docker-btrfs-error/
RM = --rm
ifeq ("$(CIRCLECI)", "true")
RM =
endif
#
# images: This target builds all IMAGES (because it is the first one, it is built by default)
#
images: $(DIRECTORIES)
#
# display
#
display_images:
for directory in $(DIRECTORIES); do echo $$directory | rev | cut -d'/' -f 1 | rev | cut -d'-' -f 2- | tr '[:upper:]' '[:lower:]'; done
$(VERBOSE).SILENT: display_images
#
# build implicit rule
#
$(DIRECTORIES): %: ../%/Dockerfile
$(eval DIR := $@)
$(eval TAG := $(shell echo $(DIR) | rev | cut -d'/' -f 1 | rev | cut -d'-' -f 2- | tr '[:upper:]' '[:lower:]'))
$(eval IMAGEID := $(shell $(DOCKER) images -q $(ORG)/$(REPO):$(TAG)))
$(DOCKER) build -t $(ORG)/$(REPO):$(TAG) \
--build-arg IMAGE=$(ORG)/$(REPO):$(TAG) \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg VCS_URL=`git config --get remote.origin.url` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
../$@
CURRENT_IMAGEID=$$($(DOCKER) images -q $(ORG)/$(REPO)) && \
if [ -n "$(IMAGEID)" ] && [ "$(IMAGEID)" != "$$CURRENT_IMAGEID" ]; then $(DOCKER) rmi "$(IMAGEID)"; fi
#
# run implicit rule
#
.SECONDEXPANSION:
$(addsuffix .run,$(DIRECTORIES)):
$(eval DIR := $(basename $@))
$(eval TAG := $(shell echo $(DIR) | rev | cut -d'/' -f 1 | rev | cut -d'-' -f 2- | tr '[:upper:]' '[:lower:]'))
$(DOCKER) run -v $$(pwd)/../..:/usr/src/SlicerExecutionModel -ti $(RM) $(ORG)/$(REPO):$(TAG) bash
#
# push implicit rule
#
.SECONDEXPANSION:
$(addsuffix .push,$(DIRECTORIES)): $$(basename $$@)
$(eval DIR := $(basename $@))
$(eval TAG := $(shell echo $(DIR) | rev | cut -d'/' -f 1 | rev | cut -d'-' -f 2- | tr '[:upper:]' '[:lower:]'))
$(DOCKER) push $(ORG)/$(REPO):$(TAG)
push: $(addsuffix .push,$(DIRECTORIES))
.PHONY: images display_images $(DIRECTORIES) $(addsuffix .run,$(DIRECTORIES)) $(addsuffix .push,$(DIRECTORIES))