7070# Specific packages can be excluded from each of the tests below by setting the *_FILTER_CMD variables
7171# to something like "| grep -v 'github.com/kubernetes-csi/project/pkg/foobar'". See usage below.
7272
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]
7474# separated by semicolon. An empty variable or empty entry (= just a
7575# semicolon) builds for the default platform of the current Go
7676# toolchain.
@@ -85,20 +85,20 @@ FULL_LDFLAGS = $(LDFLAGS) $(IMPORTPATH_LDFLAGS) $(EXT_LDFLAGS)
8585# defined by BUILD_PLATFORMS.
8686$(CMDS:% =build-%): build-%: check-go-version-go
8787 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
9090 # we don't need to build it again, this is done to avoid building
9191 # 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 *}; \
9494 if ! [ $${# os_arch_seen_pre} = $${#os_arch_seen} ]; then \
9595 continue; \
9696 fi; \
9797 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 \
9898 echo "Building $* for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \
9999 exit 1; \
100100 fi; \
101- os_arch_seen+=";$$os-$$arch"; \
101+ os_arch_seen+=";$$os-$$arch-$$buildx_platform "; \
102102 done
103103
104104$(CMDS:% =container-%): container-%: build-%
@@ -154,16 +154,17 @@ $(CMDS:%=push-multiarch-%): push-multiarch-%: check-pull-base-ref build-%
154154 dockerfile_windows=$$(if [ -e ./$(CMDS_DIR)/$*/Dockerfile.Windows ]; then echo ./$(CMDS_DIR)/$*/Dockerfile.Windows; else echo Dockerfile.Windows; fi); \
155155 if [ '$(BUILD_PLATFORMS)' ]; then build_platforms='$(BUILD_PLATFORMS)'; else build_platforms="linux amd64"; fi; \
156156 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/;[ ]*$$//')"; \
158158 fi; \
159159 pushMultiArch () { \
160160 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 \
162162 escaped_base_image=$${base_image/:/-}; \
163+ escaped_buildx_platform=$${buildx_platform//\//-}; \
163164 if ! [ -z $$escaped_base_image ]; then escaped_base_image+="-"; fi; \
164165 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 \
167168 --file $$(eval echo \$${dockerfile_$$os}) \
168169 --build-arg binary=./bin/$*$$suffix \
169170 --build-arg ARCH=$$arch \
@@ -172,13 +173,14 @@ $(CMDS:%=push-multiarch-%): push-multiarch-%: check-pull-base-ref build-%
172173 --label revision=$(REV) \
173174 .; \
174175 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 \
176177 escaped_base_image=$${base_image/:/-}; \
178+ escaped_buildx_platform=$${buildx_platform//\//-}; \
177179 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; \
179181 done); \
180182 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 \
182184 if [ $$os = "windows" ]; then \
183185 escaped_base_image=$${base_image/:/-}; \
184186 if ! [ -z $$escaped_base_image ]; then escaped_base_image+="-"; fi; \
0 commit comments