@@ -71,7 +71,7 @@ BUILD_PLATFORMS =
71
71
72
72
# This builds each command (= the sub-directories of ./cmd) for the target platform(s)
73
73
# defined by BUILD_PLATFORMS.
74
- build-% : check-go-version-go
74
+ $(CMDS:% =build-%): build-%: check-go-version-go
75
75
mkdir -p bin
76
76
echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch suffix; do \
77
77
if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o "./bin/$*$$suffix" ./cmd/$*); then \
@@ -80,10 +80,10 @@ build-%: check-go-version-go
80
80
fi; \
81
81
done
82
82
83
- container-% : build-%
83
+ $(CMDS:% =container-%): container-%: build-%
84
84
docker build -t $*:latest -f $(shell if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi) --label revision=$(REV) .
85
85
86
- push-% : container-%
86
+ $(CMDS:% =push-%): push-%: container-%
87
87
set -ex; \
88
88
push_image () { \
89
89
docker tag $*:latest $(IMAGE_NAME):$$tag; \
@@ -117,10 +117,14 @@ DOCKER_BUILDX_CREATE_ARGS ?=
117
117
# Docker Buildx is included in Docker 19.03.
118
118
#
119
119
# ./cmd/<command>/Dockerfile[.Windows] is used if found, otherwise Dockerfile[.Windows].
120
+ # It is currently optional: if no such file exists, Windows images are not included,
121
+ # even when Windows is listed in BUILD_PLATFORMS. That way, projects can test that
122
+ # Windows binaries can be built before adding a Dockerfile for it.
123
+ #
120
124
# BUILD_PLATFORMS determines which individual images are included in the multiarch image.
121
125
# PULL_BASE_REF must be set to 'master', 'release-x.y', or a tag name, and determines
122
126
# the tag for the resulting multiarch image.
123
- push-multiarch-% : check-pull-base-ref build-%
127
+ $(CMDS:% =push-multiarch-%): push-multiarch-%: check-pull-base-ref build-%
124
128
set -ex; \
125
129
DOCKER_CLI_EXPERIMENTAL=enabled; \
126
130
export DOCKER_CLI_EXPERIMENTAL; \
@@ -129,6 +133,9 @@ push-multiarch-%: check-pull-base-ref build-%
129
133
dockerfile_linux=$$(if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi); \
130
134
dockerfile_windows=$$(if [ -e ./cmd/$*/Dockerfile.Windows ]; then echo ./cmd/$*/Dockerfile.Windows; else echo Dockerfile.Windows; fi); \
131
135
if [ '$(BUILD_PLATFORMS)' ]; then build_platforms='$(BUILD_PLATFORMS)'; else build_platforms="linux amd64"; fi; \
136
+ if ! [ -f "$$dockerfile_windows" ]; then \
137
+ build_platforms="$$(echo "$$build_platforms" | sed -e 's/windows *[^ ]* *.exe//g' -e 's/; *;/;/g')"; \
138
+ fi; \
132
139
pushMultiArch () { \
133
140
tag=$$1; \
134
141
echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix; do \
@@ -166,6 +173,7 @@ check-pull-base-ref:
166
173
exit 1; \
167
174
fi
168
175
176
+ .PHONY : push-multiarch
169
177
push-multiarch : $(CMDS:%=push-multiarch-% )
170
178
171
179
clean :
0 commit comments