diff --git a/Dockerfile b/Dockerfile index e0e87af9c8..a9835d6e81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,12 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +# See +# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope +# for info on BUILDPLATFORM, TARGETOS, TARGETARCH, etc. FROM --platform=$BUILDPLATFORM golang:1.17 AS builder WORKDIR /go/src/github.com/kubernetes-sigs/aws-ebs-csi-driver COPY . . -ARG OS -ARG ARCH -RUN make $OS/$ARCH +ARG TARGETOS +ARG TARGETARCH +RUN OS=$TARGETOS ARCH=$TARGETARCH make $TARGETOS/$TARGETARCH FROM amazonlinux:2 AS linux-amazon RUN yum update -y && \ diff --git a/Makefile b/Makefile index 86b4c84866..987fc96329 100644 --- a/Makefile +++ b/Makefile @@ -40,9 +40,11 @@ ALL_OS?=linux windows ALL_ARCH_linux?=amd64 arm64 ALL_OSVERSION_linux?=amazon ALL_OS_ARCH_OSVERSION_linux=$(foreach arch, $(ALL_ARCH_linux), $(foreach osversion, ${ALL_OSVERSION_linux}, linux-$(arch)-${osversion})) + ALL_ARCH_windows?=amd64 ALL_OSVERSION_windows?=1809 2004 20H2 ALL_OS_ARCH_OSVERSION_windows=$(foreach arch, $(ALL_ARCH_windows), $(foreach osversion, ${ALL_OSVERSION_windows}, windows-$(arch)-${osversion})) + ALL_OS_ARCH_OSVERSION=$(foreach os, $(ALL_OS), ${ALL_OS_ARCH_OSVERSION_${os}}) # split words on hyphen, access by 1-index @@ -84,7 +86,7 @@ annotate-manifest: .annotate-manifest-$(OS)-$(ARCH)-$(OSVERSION) .annotate-manifest-$(OS)-$(ARCH)-$(OSVERSION): set -x; docker manifest annotate --os $(OS) --arch $(ARCH) --os-version $(OSVERSION) $(IMAGE):$(TAG) $(IMAGE):$(TAG)-$(OS)-$(ARCH)-$(OSVERSION) -# only linux for OUTPUT_TYPE=docker because windows image cannot be exported +# Only linux for OUTPUT_TYPE=docker because windows image cannot be exported # "Currently, multi-platform images cannot be exported with the docker export type. The most common usecase for multi-platform images is to directly push to a registry (see registry)." # https://docs.docker.com/engine/reference/commandline/buildx_build/#output all-image-docker: $(addprefix sub-image-docker-,$(ALL_OS_ARCH_OSVERSION_linux)) @@ -97,8 +99,6 @@ image: .image-$(TAG)-$(OS)-$(ARCH)-$(OSVERSION) .image-$(TAG)-$(OS)-$(ARCH)-$(OSVERSION): docker buildx build \ --platform=$(OS)/$(ARCH) \ - --build-arg OS=$(OS) \ - --build-arg ARCH=$(ARCH) \ --progress=plain \ --target=$(OS)-$(OSVERSION) \ --output=type=$(OUTPUT_TYPE) \