70
70
# Specific packages can be excluded from each of the tests below by setting the *_FILTER_CMD variables
71
71
# to something like "| grep -v 'github.com/kubernetes-csi/project/pkg/foobar'". See usage below.
72
72
73
- # BUILD_PLATFORMS contains a set of tuples [os arch suffix base_image addon_image]
73
+ # BUILD_PLATFORMS contains a set of tuples [os arch buildx_platform suffix base_image addon_image]
74
74
# separated by semicolon. An empty variable or empty entry (= just a
75
75
# semicolon) builds for the default platform of the current Go
76
76
# toolchain.
@@ -85,20 +85,20 @@ FULL_LDFLAGS = $(LDFLAGS) $(IMPORTPATH_LDFLAGS) $(EXT_LDFLAGS)
85
85
# defined by BUILD_PLATFORMS.
86
86
$(CMDS:% =build-%): build-%: check-go-version-go
87
87
mkdir -p bin
88
- # os_arch_seen captures all of the $$os-$$arch seen for the current binary
89
- # that we want to build, if we've seen an $$os-$$arch before it means that
88
+ # os_arch_seen captures all of the $$os-$$arch-$$buildx_platform seen for the current binary
89
+ # that we want to build, if we've seen an $$os-$$arch-$$buildx_platform before it means that
90
90
# we don't need to build it again, this is done to avoid building
91
91
# the windows binary multiple times (see the default value of $$BUILD_PLATFORMS)
92
- export os_arch_seen="" && echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch suffix base_image addon_image; do \
93
- os_arch_seen_pre=$${os_arch_seen%%$$os-$$arch*}; \
92
+ export os_arch_seen="" && echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch buildx_platform suffix base_image addon_image; do \
93
+ os_arch_seen_pre=$${os_arch_seen%%$$os-$$arch-$$buildx_platform *}; \
94
94
if ! [ $${# os_arch_seen_pre} = $${#os_arch_seen} ]; then \
95
95
continue; \
96
96
fi; \
97
97
if ! (set -x; cd ./$(CMDS_DIR)/$* && CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '$(FULL_LDFLAGS)' -o "$(abspath ./bin)/$*$$suffix" .); then \
98
98
echo "Building $* for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \
99
99
exit 1; \
100
100
fi; \
101
- os_arch_seen+=";$$os-$$arch"; \
101
+ os_arch_seen+=";$$os-$$arch-$$buildx_platform "; \
102
102
done
103
103
104
104
$(CMDS:% =container-%): container-%: build-%
@@ -154,16 +154,17 @@ $(CMDS:%=push-multiarch-%): push-multiarch-%: check-pull-base-ref build-%
154
154
dockerfile_windows=$$(if [ -e ./$(CMDS_DIR)/$*/Dockerfile.Windows ]; then echo ./$(CMDS_DIR)/$*/Dockerfile.Windows; else echo Dockerfile.Windows; fi); \
155
155
if [ '$(BUILD_PLATFORMS)' ]; then build_platforms='$(BUILD_PLATFORMS)'; else build_platforms="linux amd64"; fi; \
156
156
if ! [ -f "$$dockerfile_windows" ]; then \
157
- build_platforms="$$(echo "$$build_platforms" | sed -e 's/windows *[^ ]* *.exe *[^ ]* *[^ ]*//g' -e 's/; *;/;/g' -e 's/;[ ]*$$//')"; \
157
+ build_platforms="$$(echo "$$build_platforms" | sed -e 's/windows *[^ ]* *[^ ]* * .exe *[^ ]* *[^ ]*//g' -e 's/; *;/;/g' -e 's/;[ ]*$$//')"; \
158
158
fi; \
159
159
pushMultiArch () { \
160
160
tag=$$1; \
161
- echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix base_image addon_image; do \
161
+ echo "$$build_platforms" | tr ';' '\n' | while read -r os arch buildx_platform suffix base_image addon_image; do \
162
162
escaped_base_image=$${base_image/:/-}; \
163
+ escaped_buildx_platform=$${buildx_platform//\//-}; \
163
164
if ! [ -z $$escaped_base_image ]; then escaped_base_image+="-"; fi; \
164
165
docker buildx build --push \
165
- --tag $(IMAGE_NAME):$$arch -$$os-$$escaped_base_image$$tag \
166
- --platform=$$os/$$arch \
166
+ --tag $(IMAGE_NAME):$$escaped_buildx_platform -$$os-$$escaped_base_image$$tag \
167
+ --platform=$$os/$$buildx_platform \
167
168
--file $$(eval echo \$${dockerfile_$$os}) \
168
169
--build-arg binary=./bin/$*$$suffix \
169
170
--build-arg ARCH=$$arch \
@@ -172,13 +173,14 @@ $(CMDS:%=push-multiarch-%): push-multiarch-%: check-pull-base-ref build-%
172
173
--label revision=$(REV) \
173
174
.; \
174
175
done; \
175
- images=$$(echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix base_image addon_image; do \
176
+ images=$$(echo "$$build_platforms" | tr ';' '\n' | while read -r os arch buildx_platform suffix base_image addon_image; do \
176
177
escaped_base_image=$${base_image/:/-}; \
178
+ escaped_buildx_platform=$${buildx_platform//\//-}; \
177
179
if ! [ -z $$escaped_base_image ]; then escaped_base_image+="-"; fi; \
178
- echo $(IMAGE_NAME):$$arch -$$os-$$escaped_base_image$$tag; \
180
+ echo $(IMAGE_NAME):$$escaped_buildx_platform -$$os-$$escaped_base_image$$tag; \
179
181
done); \
180
182
docker manifest create --amend $(IMAGE_NAME):$$tag $$images; \
181
- echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix base_image addon_image; do \
183
+ echo "$$build_platforms" | tr ';' '\n' | while read -r os arch buildx_platform suffix base_image addon_image; do \
182
184
if [ $$os = "windows" ]; then \
183
185
escaped_base_image=$${base_image/:/-}; \
184
186
if ! [ -z $$escaped_base_image ]; then escaped_base_image+="-"; fi; \
0 commit comments