@@ -29,6 +29,13 @@ TAGS ?= alpine$(ALPINE_VER)-r$(BUILD_REV) \
2929 alpine \
3030 latest
3131VERSION ?= $(word 1,$(subst $(comma ) , ,$(TAGS ) ) )
32+ PLATFORMS ?= linux/amd64 \
33+ linux/arm64 \
34+ linux/arm/v6 \
35+ linux/arm/v7 \
36+ linux/ppc64le \
37+ linux/s390x
38+ MAIN_PLATFORM ?= $(word 1,$(subst $(comma ) , ,$(PLATFORMS ) ) )
3239
3340
3441
@@ -43,8 +50,6 @@ push: docker.push
4350
4451release : git.release
4552
46- tags : docker.tags
47-
4853test : test.docker
4954
5055
@@ -58,62 +63,86 @@ docker-namespaces = $(strip $(if $(call eq,$(namespaces),),\
5863 $(NAMESPACES ) ,$(subst $(comma ) , ,$(namespaces ) ) ) )
5964docker-tags = $(strip $(if $(call eq,$(tags ) ,) ,\
6065 $(TAGS ) ,$(subst $(comma ) , ,$(tags ) ) ) )
66+ docker-platforms = $(strip $(if $(call eq,$(platforms ) ,) ,\
67+ $(PLATFORMS ) ,$(subst $(comma ) , ,$(platforms ) ) ) )
6168
62-
63- # Build Docker image with the given tag .
64- #
65- # Usage:
66- # make docker.image [ tag=($(VERSION)|<docker-tag>)]] [no-cache=(no|yes)]
67- # [ALPINE_VER=<alpine-version>]
68- # [BUILD_REV=<build-revision>]
69-
70- docker.image :
71- docker build --network=host --force-rm \
69+ # Runs `docker buildx build` command allowing to customize it for the purpose of
70+ # re-tagging or pushing .
71+ define docker.buildx
72+ $( eval namespace := $( strip $( 1 ) ) )
73+ $( eval tag := $( strip $( 2 ) ) )
74+ $( eval platform := $( strip $( 3 ) ) )
75+ $( eval no-cache := $( strip $( 4 ) ) )
76+ $( eval args := $( strip $( 5 ) ) )
77+ docker buildx build --force-rm $( args ) \
78+ --platform $( platform ) \
7279 $(if $(call eq,$(no-cache ) ,yes) ,--no-cache --pull,) \
7380 --build-arg alpine_ver=$(ALPINE_VER ) \
7481 --build-arg build_rev=$(BUILD_REV ) \
75- -t instrumentisto/$(NAME ) :$(if $(call eq,$(tag ) ,) ,$(VERSION ) ,$(tag ) ) ./
82+ -t $(namespace ) /$(NAME ) :$(tag ) .
83+ endef
7684
7785
78- # Manually push Docker images to container registries.
86+ # Pre-build cache for Docker image builds.
87+ #
88+ # WARNING: This command doesn't apply tag to the built Docker image, just
89+ # creates a build cache. To produce a Docker image with a tag, use
90+ # `docker.tag` command right after running this one.
91+ #
92+ # Usage:
93+ # make docker.build.cache
94+ # [platforms=($(PLATFORMS)|<platform-1>[,<platform-2>...])]
95+ # [no-cache=(no|yes)]
96+ # [ALPINE_VER=<alpine-version>]
97+ # [BUILD_REV=<build-revision>]
98+
99+ docker.build.cache :
100+ $(call docker.buildx,\
101+ instrumentisto,\
102+ build-cache,\
103+ $(shell echo "$(docker-platforms ) " | tr -s '[:blank:]' ',') ,\
104+ $(no-cache ) ,\
105+ --output ' type=image$(comma)push=false' )
106+
107+
108+ # Build Docker image on the given platform with the given tag.
79109#
80110# Usage:
81- # make docker.push [tags=($(TAGS)|<docker-tag-1>[,<docker-tag-2>...])]
82- # [namespaces=($(NAMESPACES)|<prefix-1>[,<prefix-2>...])]
111+ # make docker.image
112+ # [tag=($(VERSION)|<tag>)]
113+ # [platform=($(MAIN_PLATFORM)|<platform>)]
114+ # [no-cache=(no|yes)]
115+ # [ALPINE_VER=<alpine-version>]
116+ # [BUILD_REV=<build-revision>]
83117
84- docker.push :
85- $(foreach tag,$(subst $(comma ) , ,$(docker-tags ) ) ,\
86- $(foreach namespace,$(subst $(comma ) , ,$(docker-namespaces ) ) ,\
87- $(call docker.push.do,$(namespace ) ,$(tag ) ) ))
88- define docker.push.do
89- $(eval repo := $(strip $(1 ) ) )
90- $(eval tag := $(strip $(2 ) ) )
91- docker push $(repo ) /$(NAME ) :$(tag )
92- endef
118+ docker.image :
119+ $(call docker.buildx,\
120+ instrumentisto,\
121+ $(if $(call eq,$(tag ) ,) ,$(VERSION ) ,$(tag ) ) ,\
122+ $(if $(call eq,$(platform ) ,) ,$(MAIN_PLATFORM ) ,$(platform ) ) ,\
123+ $(no-cache ) ,\
124+ --load)
93125
94126
95- # Tag Docker image with the given tags.
127+ # Push Docker images to their repositories (container registries),
128+ # along with the required multi-arch manifests.
96129#
97130# Usage:
98- # make docker.tags [of=($(VERSION)|<docker-tag>)]
99- # [tags=($(TAGS)|<docker-tag-1>[,<docker-tag-2>...])]
100- # [namespaces=($(NAMESPACES)|<prefix-1>[,<prefix-2>...])]
101-
102- docker-tags-of = $(if $(call eq,$(of ) ,) ,$(VERSION ) ,$(of ) )
103-
104- docker.tags :
105- $(foreach tag,$(subst $(comma ) , ,$(docker-tags ) ) ,\
106- $(foreach namespace,$(subst $(comma ) , ,$(docker-namespaces ) ) ,\
107- $(call docker.tags.do,$(docker-tags-of ) ,$(namespace ) ,$(tag ) ) ))
108- define docker.tags.do
109- $(eval from := $(strip $(1 ) ) )
110- $(eval repo := $(strip $(2 ) ) )
111- $(eval to := $(strip $(3 ) ) )
112- docker tag instrumentisto/$(NAME ) :$(from ) $(repo ) /$(NAME ) :$(to )
113- endef
114-
131+ # make docker.push
132+ # [namespaces=($(NAMESPACES)|<prefix-1>[,<prefix-2>...])]
133+ # [tags=($(TAGS)|<tag-1>[,<tag-2>...])]
134+ # [platforms=($(PLATFORMS)|<platform-1>[,<platform-2>...])]
135+ # [ALPINE_VER=<alpine-version>]
136+ # [BUILD_REV=<build-revision>]
115137
116- docker.test : test.docker
138+ docker.push :
139+ $(foreach namespace,$(docker-namespaces ) ,\
140+ $(foreach tag,$(docker-tags ) ,\
141+ $(call docker.buildx,\
142+ $(namespace ) ,\
143+ $(tag ) ,\
144+ $(shell echo "$(docker-platforms ) " | tr -s '[:blank:]' ',') ,,\
145+ --push)))
117146
118147
119148
@@ -128,16 +157,37 @@ docker.test: test.docker
128157# https://github.com/bats-core/bats-core
129158#
130159# Usage:
131- # make test.docker [tag=($(VERSION)|<tag>)]
132-
160+ # make test.docker
161+ # [tag=($(VERSION)|<tag>)]
162+ # [platforms=($(MAIN_PLATFORM)|@all|<platform-1>[,<platform-2>...])]
163+ # [( [build=no]
164+ # | build=yes [HARAKA_VER=<haraka-version>]
165+ # [NODE_VER=<node-version>]
166+ # [BUILD_REV=<build-revision>] )]
167+
168+ test-docker-platforms = $(strip $(if $(call eq,$(platforms ) ,) ,$(MAIN_PLATFORM ) ,\
169+ $(if $(call eq,$(platforms ) ,@all) ,$(PLATFORMS ) ,\
170+ $(docker-platforms ) ) ) )
133171test.docker :
134172ifeq ($(wildcard node_modules/.bin/bats) ,)
135173 @make npm.install
136174endif
137- IMAGE=instrumentisto/$(NAME):$(if $(call eq,$(tag),),$(VERSION),$(tag)) \
175+ $(foreach platform,$(test-docker-platforms),\
176+ $(call test.docker.do,\
177+ $(if $(call eq,$(tag),),$(VERSION),$(tag)),\
178+ $(platform)))
179+ define test.docker.do
180+ $(eval tag := $(strip $(1 ) ) )
181+ $(eval platform := $(strip $(2 ) ) )
182+ $(if $(call eq,$(build ) ,yes) ,\
183+ @make docker.image no-cache=no tag=$(tag ) platform=$(platform ) \
184+ ALPINE_VER=$(ALPINE_VER ) \
185+ BUILD_REV=$(BUILD_REV ) ,)
186+ IMAGE=instrumentisto/$(NAME ) :$(tag ) PLATFORM=$(platform ) \
138187 node_modules/.bin/bats \
139188 --timing $(if $(call eq,$(CI ) ,) ,--pretty,--formatter tap) \
140189 tests/main.bats
190+ endef
141191
142192
143193
@@ -188,8 +238,8 @@ endif
188238# .PHONY section #
189239# #################
190240
191- .PHONY : image push release tags test \
192- docker.image docker.push docker.tags docker.test \
241+ .PHONY : image push release test \
242+ docker.build.cache docker.image docker.push \
193243 git.release \
194244 npm.install \
195245 test.docker
0 commit comments