-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
181 lines (145 loc) · 9.17 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
#
# Linux container images Makefile
#
# Run `make` to build all linux container images
# Run `make spotfire-server` to build just spotfire-server
SHELL = /bin/bash
.SHELLFLAGS = -o pipefail -c
.DEFAULT_GOAL = build
DOCKER_CLI ?= docker# podman
DOCKER_CLI_BUILD_ARGS ?= # --no-cache
IMAGE_REPOSITORY_PREFIX ?= spotfire
DOWNLOADS_DIR ?= downloads
IMAGES_DIR ?= images
ARCH_TARGET := linux/amd64
include ../versions.mk
include build-files.mk
#
# Image dependencies
#
.SECONDEXPANSION : $(IMAGE_TARGETS)
IMAGE_TARGETS += spotfire-server spotfire-config spotfire-nodemanager spotfire-base spotfire-workerhost \
spotfire-webplayer spotfire-automationservices spotfire-terrservice spotfire-pythonservice \
spotfire-rservice spotfire-deployment
spotfire-server spotfire-config spotfire-nodemanager spotfire-deployment : spotfire-base
spotfire-terrservice spotfire-pythonservice spotfire-rservice : spotfire-nodemanager
spotfire-workerhost : spotfire-nodemanager
spotfire-automationservices spotfire-webplayer : spotfire-workerhost
NONLOCAL_TARGETS = $(filter-out spotfire-workerhost spotfire-nodemanager spotfire-base,$(IMAGE_TARGETS))
.PHONY : $(IMAGE_TARGETS)
#
# Build files - copy files from downloads/ to images/<imagename>/build
#
# Image should depend on all BUILD_FILES that start with path images/<imagename>/build/
$(IMAGE_TARGETS) : % : $$(filter images/%/$$(PERCENT),$(BUILD_FILES))
$(IMAGE_TARGETS) : PERCENT := %
$(BUILD_FILES) : % : $(DOWNLOADS_DIR)/$$(notdir %)
cp -p "$<" "$@"
downloads-list : DOWNLOADS_FILES = $(addprefix $(DOWNLOADS_DIR)/,$(sort $(foreach file,$(BUILD_FILES),$(notdir $(file)))))
downloads-list :
@$(foreach file,$(DOWNLOADS_FILES),echo $(file);)
build-files : $(BUILD_FILES)
.PHONY : build-files downloads-list
#
# Docker cli build and arguments
#
.PHONY : build
build : $(IMAGE_TARGETS)
$(IMAGE_TARGETS) : BUILD_TAG_ARGUMENT = $(IMAGE_REPOSITORY_PREFIX)/$(@):$(IMAGE_TAG)
$(IMAGE_TARGETS) : BUILD_ARGS = $(DOCKER_CLI_BUILD_ARGS) $(addprefix --build-arg ,$(IMAGE_BUILD_ARGS))
$(IMAGE_TARGETS) :
$(DOCKER_CLI) build --platform $(ARCH_TARGET) $(BUILD_ARGS) --tag $(BUILD_TAG_ARGUMENT) $(IMAGES_DIR)/$(@)
# TAG_SUFFIX can be used to override *_CONTAINER_ITERATION
TAG_SUFFIX ?= $(or $1,$(IMAGE_BUILD_ID))
SPOTFIRE_AUTOMATIONSERVICES_IMAGE_TAG = $(SPOTFIRE_NETCORE_VERSION)$(addprefix -,$(or $(TAG_SUFFIX),$(SPOTFIRE_AUTOMATIONSERVICES_CONTAINER_ITERATION)))
SPOTFIRE_BASE_IMAGE_TAG = $(or $(IMAGE_BUILD_ID),base)
SPOTFIRE_CONFIG_IMAGE_TAG = $(SPOTFIRE_SERVER_VERSION)$(addprefix -,$(or $(TAG_SUFFIX),$(SPOTFIRE_CONFIG_CONTAINER_ITERATION)))
SPOTFIRE_SERVER_VERSION ?= 1.0.0
TAG_SUFFIX ?=
SPOTFIRE_SERVER_CONTAINER_ITERATION ?= 1
SPOTFIRE_SERVER_IMAGE_TAG = $(SPOTFIRE_SERVER_VERSION)$(addprefix -,$(or $(TAG_SUFFIX),$(SPOTFIRE_SERVER_CONTAINER_ITERATION)))
SPOTFIRE_NODEMANAGER_IMAGE_TAG = $(or $(IMAGE_BUILD_ID),nodemanager)
SPOTFIRE_WORKERHOST_IMAGE_TAG = $(or $(IMAGE_BUILD_ID),workerhost)
SPOTFIRE_PYTHONSERVICE_IMAGE_TAG = $(SPOTFIRE_PYTHONSERVICE_VERSION)$(addprefix -,$(or $(TAG_SUFFIX),$(SPOTFIRE_PYTHONSERVICE_CONTAINER_ITERATION)))
SPOTFIRE_TERRSERVICE_IMAGE_TAG = $(SPOTFIRE_TERRSERVICE_VERSION)$(addprefix -,$(or $(TAG_SUFFIX),$(SPOTFIRE_TERRSERVICE_CONTAINER_ITERATION)))
SPOTFIRE_RSERVICE_IMAGE_TAG = $(SPOTFIRE_RSERVICE_VERSION)$(addprefix -,$(or $(TAG_SUFFIX),$(SPOTFIRE_RSERVICE_CONTAINER_ITERATION)))
SPOTFIRE_WEBPLAYER_IMAGE_TAG = $(SPOTFIRE_NETCORE_VERSION)$(addprefix -,$(or $(TAG_SUFFIX),$(SPOTFIRE_WEBPLAYER_CONTAINER_ITERATION)))
SPOTFIRE_DEPLOYMENT_IMAGE_TAG = $(SPOTFIRE_DEPLOYMENT_VERSION)$(addprefix -,$(or $(TAG_SUFFIX),$(SPOTFIRE_WEBPLAYER_CONTAINER_ITERATION)))
%potfire-automationservices : IMAGE_TAG = $(SPOTFIRE_AUTOMATIONSERVICES_IMAGE_TAG)
%potfire-base : IMAGE_TAG = $(SPOTFIRE_BASE_IMAGE_TAG)
%potfire-config : IMAGE_TAG = $(SPOTFIRE_CONFIG_IMAGE_TAG)
%potfire-server : IMAGE_TAG = $(SPOTFIRE_SERVER_IMAGE_TAG)
%potfire-nodemanager : IMAGE_TAG = $(SPOTFIRE_NODEMANAGER_IMAGE_TAG)
%potfire-workerhost : IMAGE_TAG = $(SPOTFIRE_WORKERHOST_IMAGE_TAG)
%potfire-pythonservice : IMAGE_TAG = $(SPOTFIRE_PYTHONSERVICE_IMAGE_TAG)
%potfire-terrservice : IMAGE_TAG = $(SPOTFIRE_TERRSERVICE_IMAGE_TAG)
%potfire-rservice : IMAGE_TAG = $(SPOTFIRE_RSERVICE_IMAGE_TAG)
%potfire-webplayer : IMAGE_TAG = $(SPOTFIRE_WEBPLAYER_IMAGE_TAG)
%potfire-deployment : IMAGE_TAG = $(SPOTFIRE_DEPLOYMENT_IMAGE_TAG)
# --build-arg image tags
spotfire-base: private IMAGE_BUILD_ARGS += $(addprefix DEBIAN_IMAGE_TAG=,$(DEBIAN_IMAGE_TAG))
spotfire-server spotfire-config spotfire-nodemanager spotfire-deployment : private IMAGE_BUILD_ARGS += "SPOTFIRE_BASE_IMAGE_TAG=$(SPOTFIRE_BASE_IMAGE_TAG)"
spotfire-pythonservice spotfire-terrservice spotfire-rservice : private IMAGE_BUILD_ARGS += "SPOTFIRE_NODEMANAGER_IMAGE_TAG=$(SPOTFIRE_NODEMANAGER_IMAGE_TAG)"
spotfire-workerhost : private IMAGE_BUILD_ARGS += "SPOTFIRE_NODEMANAGER_IMAGE_TAG=$(SPOTFIRE_NODEMANAGER_IMAGE_TAG)"
spotfire-webplayer spotfire-automationservices : private IMAGE_BUILD_ARGS += "SPOTFIRE_WORKERHOST_IMAGE_TAG=$(SPOTFIRE_WORKERHOST_IMAGE_TAG)"
# --build-arg product versions
spotfire-nodemanager : private IMAGE_BUILD_ARGS += "SPOTFIRE_NODEMANAGER_VERSION=$(SPOTFIRE_NODEMANAGER_VERSION)"
spotfire-server spotfire-config : private IMAGE_BUILD_ARGS += "SPOTFIRE_SERVER_VERSION=$(SPOTFIRE_SERVER_VERSION)"
spotfire-webplayer spotfire-automationservices : private IMAGE_BUILD_ARGS += "SPOTFIRE_NETCORE_VERSION=$(SPOTFIRE_NETCORE_VERSION)"
spotfire-webplayer spotfire-automationservices spotfire-deployment : private IMAGE_BUILD_ARGS += "SPOTFIRE_NETCORE_LANGUAGEPACKS_VERSION=$(SPOTFIRE_NETCORE_LANGUAGEPACKS_VERSION)"
spotfire-deployment : private IMAGE_BUILD_ARGS += "SPOTFIRE_DEPLOYMENT_VERSION=$(SPOTFIRE_DEPLOYMENT_VERSION)"
spotfire-terrservice : private IMAGE_BUILD_ARGS += "SPOTFIRE_TERRSERVICE_VERSION=$(SPOTFIRE_TERRSERVICE_VERSION)"
spotfire-rservice : private IMAGE_BUILD_ARGS += "SPOTFIRE_RSERVICE_VERSION=$(SPOTFIRE_RSERVICE_VERSION)"
spotfire-pythonservice : private IMAGE_BUILD_ARGS += "SPOTFIRE_PYTHONSERVICE_VERSION=$(SPOTFIRE_PYTHONSERVICE_VERSION)"
#
# tag, push, list
#
# REMOTE_IMAGE_BUILD_ID: push this destination build id
# LOCAL_IMAGE_BUILD_ID: push this source build id
REMOTE_IMAGE_REFERENCE = $(addsuffix /,$(CONTAINER_REGISTRY))$(IMAGE_REPOSITORY_PREFIX)/$(*):$(call IMAGE_TAG,$(REMOTE_IMAGE_BUILD_ID))
LOCAL_IMAGE_REFERENCE = $(addsuffix /,$(LOCAL_CONTAINER_REGISTRY))$(IMAGE_REPOSITORY_PREFIX)/$(*):$(call IMAGE_TAG,$(LOCAL_IMAGE_BUILD_ID))
push : $(addprefix push-,$(NONLOCAL_TARGETS))
push-% : CONTAINER_REGISTRY ?= $(error CONTAINER_REGISTRY is unset)
push-% :
$(DOCKER_CLI) tag $(LOCAL_IMAGE_REFERENCE) $(REMOTE_IMAGE_REFERENCE)
$(DOCKER_CLI) push $(REMOTE_IMAGE_REFERENCE)
$(DOCKER_CLI) rmi $(REMOTE_IMAGE_REFERENCE)
# make CONTAINER_REGISTRY=registry.com list
list-images : $(addprefix list-image-,$(NONLOCAL_TARGETS))
list-image-% :
@echo $(REMOTE_IMAGE_REFERENCE)
# source <(make --silent list-tags)
list-tags : create_var_assignment = $(if $(filter $(EXPORT),1),export ,)$(shell echo '$(*)' | tr '[:lower:]-' '[:upper:]_')_$(1)=$(2)
list-tags : $(addprefix list-tag-,$(NONLOCAL_TARGETS))
list-tag-% :
@echo $(call create_var_assignment,IMAGE_TAG,$(IMAGE_TAG))
# pull + push can be used to copy images from one place to the other
# 1. make pull --dry-run IMAGE_BUILD_ID=<source-tag> CONTAINER_REGISTRY=<source-registry>
# 2. LOCAL_IMAGE_BUILD_ID=<source-tag> IMAGE_BUILD_ID= make push --dry-run CONTAINER_REGISTRY=<destination-registry>
pull : $(addprefix pull-,$(NONLOCAL_TARGETS))
pull-% :
$(DOCKER_CLI) pull $(REMOTE_IMAGE_REFERENCE)
.PHONY : push push-% list list-%
#
# additional targets
#
licenses licenses-% : LICENSE_DIR = licenses/$(*)
licenses : $(addprefix licenses-,$(filter-out spotfire-base spotfire-deployment,$(NONLOCAL_TARGETS)))
$(info Licenses exported to $(LICENSE_DIR))
@find $(LICENSE_DIR) -type f
licenses-% :
mkdir -p $(LICENSE_DIR)
tc=$$($(DOCKER_CLI) create "$(IMAGE_REPOSITORY_PREFIX)/$(*):$(IMAGE_TAG)"); \
$(DOCKER_CLI) export $${tc} | tar --strip-components=3 -C $(LICENSE_DIR) --wildcards -x "*license.pdf"; \
$(DOCKER_CLI) rm $${tc}
# echos the value of given variable
# make variable VAR=SPOTFIRE_DEPLOYMENT_VERSION
variable :
@echo "$($(VAR))"
clean : $(addprefix clean-,$(NONLOCAL_TARGETS))
rm -f $(BUILD_FILES)
rm -f $(IMAGES_DIR)/**/build/*
rm -rf licenses/
clean-% :
$(DOCKER_CLI) rmi $(REMOTE_IMAGE_REFERENCE) 2>/dev/null || :
.PHONY : clean clean-% licenses licenses-% variable