From b92605f5fc776860ffea29c7b81bf86531938290 Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Tue, 19 Nov 2024 16:45:34 +0800 Subject: [PATCH 1/4] build hybrid image Signed-off-by: Lyndon-Li --- Makefile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Makefile b/Makefile index 98fd436eb4..9a5dd768ad 100644 --- a/Makefile +++ b/Makefile @@ -198,6 +198,31 @@ container: ifneq ($(BUILDX_ENABLED), true) $(error $(BUILDX_ERROR)) endif + @docker buildx rm velero-$(BIN)-builder || true + @docker buildx create --use --name=velero-$(BIN)-builder + $(MAKE) container-linux + + for osversion in $(ALL_OSVERSIONS.windows); do \ + OSVERSION=$${osversion} $(MAKE) container-windows; \ + done + +container-linux: + @docker buildx build --pull \ + --output=type=$(BUILDX_OUTPUT_TYPE) \ + --platform $(BUILDX_PLATFORMS) \ + $(addprefix -t , $(IMAGE_TAGS)) \ + $(addprefix -t , $(GCR_IMAGE_TAGS)) \ + --build-arg=GOPROXY=$(GOPROXY) \ + --build-arg=PKG=$(PKG) \ + --build-arg=BIN=$(BIN) \ + --build-arg=VERSION=$(VERSION) \ + --build-arg=GIT_SHA=$(GIT_SHA) \ + --build-arg=GIT_TREE_STATE=$(GIT_TREE_STATE) \ + --build-arg=REGISTRY=$(REGISTRY) \ + --build-arg=RESTIC_VERSION=$(RESTIC_VERSION) \ + -f $(VELERO_DOCKERFILE) . + +container-windows: @docker buildx build --pull \ --output=type=$(BUILDX_OUTPUT_TYPE) \ --platform $(BUILDX_PLATFORMS) \ @@ -212,6 +237,7 @@ endif --build-arg=REGISTRY=$(REGISTRY) \ --build-arg=RESTIC_VERSION=$(RESTIC_VERSION) \ -f $(VELERO_DOCKERFILE) . + @echo "container: $(IMAGE):$(VERSION)" ifeq ($(BUILDX_OUTPUT_TYPE)_$(REGISTRY), registry_velero) docker pull $(IMAGE):$(VERSION) From 18b3d96e64f309a47ea044ab10595da635d8c774 Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Thu, 21 Nov 2024 10:37:42 +0800 Subject: [PATCH 2/4] build hybrid image Signed-off-by: Lyndon-Li --- Dockerfile-Windows | 58 ++++++++++++++++++++++++++++ Makefile | 96 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 137 insertions(+), 17 deletions(-) create mode 100644 Dockerfile-Windows diff --git a/Dockerfile-Windows b/Dockerfile-Windows new file mode 100644 index 0000000000..3bfcf222b8 --- /dev/null +++ b/Dockerfile-Windows @@ -0,0 +1,58 @@ +# Copyright 2020 the Velero contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ARG OS_VERSION=1809 + +# Velero binary build section +FROM --platform=$BUILDPLATFORM golang:1.22-bookworm AS velero-builder + +ARG GOPROXY +ARG BIN +ARG PKG +ARG VERSION +ARG REGISTRY +ARG GIT_SHA +ARG GIT_TREE_STATE +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT + +ENV CGO_ENABLED=0 \ + GO111MODULE=on \ + GOPROXY=${GOPROXY} \ + GOOS=${TARGETOS} \ + GOARCH=${TARGETARCH} \ + GOARM=${TARGETVARIANT} \ + LDFLAGS="-X ${PKG}/pkg/buildinfo.Version=${VERSION} -X ${PKG}/pkg/buildinfo.GitSHA=${GIT_SHA} -X ${PKG}/pkg/buildinfo.GitTreeState=${GIT_TREE_STATE} -X ${PKG}/pkg/buildinfo.ImageRegistry=${REGISTRY}" + +WORKDIR /go/src/github.com/vmware-tanzu/velero + +RUN apt-get update && apt-get install -y jq + +COPY . /go/src/github.com/vmware-tanzu/velero + +RUN mkdir -p /output/usr/bin && \ + export GOARM=$( echo "${GOARM}" | cut -c2-) && \ + go build -o /output/${BIN}.exe \ + -ldflags "${LDFLAGS}" ${PKG}/cmd/${BIN} && \ + go build -o /output/velero-helper.exe \ + -ldflags "${LDFLAGS}" ${PKG}/cmd/velero-helper && \ + go clean -modcache -cache + +# Velero image packing section +FROM mcr.microsoft.com/windows/nanoserver:${OS_VERSION} +ENTRYPOINT [ "velero.exe" ] +COPY --from=velero-builder /output / + +USER ContainerUser \ No newline at end of file diff --git a/Makefile b/Makefile index 0efe55f846..4c9030e5cb 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ GCR_IMAGE ?= $(GCR_REGISTRY)/$(BIN) # We allow the Dockerfile to be configurable to enable the use of custom Dockerfiles # that pull base images from different registries. VELERO_DOCKERFILE ?= Dockerfile +VELERO_DOCKERFILE_WINDOWS ?= Dockerfile-Windows BUILDER_IMAGE_DOCKERFILE ?= hack/build-image/Dockerfile # Calculate the realpath of the build-image Dockerfile as we `cd` into the hack/build @@ -100,9 +101,32 @@ comma=, RESTIC_VERSION ?= 0.15.0 CLI_PLATFORMS ?= linux-amd64 linux-arm linux-arm64 darwin-amd64 darwin-arm64 windows-amd64 linux-ppc64le -BUILDX_PLATFORMS ?= $(subst -,/,$(ARCH)) BUILDX_PUSH ?= false -BUILDX_OUTPUT_TYPE ?= image$(subst false,,$(subst true,$(comma)push=true,$(BUILDX_PUSH))) +BUILDX_BUILD_OS ?= linux +BUILDX_BUILD_ARCH ?= amd64 +BUILDX_TAG_GCR ?= false +BUILDX_WINDOWS_VERSION ?= ltsc2022 + +ifneq ($(BUILDX_PUSH), true) + ALL_OS = linux + ALL_ARCH.linux = $(word 2, $(subst -, ,$(shell go env GOOS)-$(shell go env GOARCH))) + BUILDX_OUTPUT_TYPE = docker +else + ALL_OS = $(subst $(comma), ,$(BUILDX_BUILD_OS)) + ALL_ARCH.linux = $(subst $(comma), ,$(BUILDX_BUILD_ARCH)) + BUILDX_OUTPUT_TYPE = registry +endif + +ALL_ARCH.windows = $(if $(filter windows,$(ALL_OS)),amd64,) +ALL_OSVERSIONS.windows = $(if $(filter windows,$(ALL_OS)),$(BUILDX_WINDOWS_VERSION),) +ALL_OS_ARCH.linux = $(foreach os, $(filter linux,$(ALL_OS)), $(foreach arch, ${ALL_ARCH.linux}, ${os}-$(arch))) +ALL_OS_ARCH.windows = $(foreach os, $(filter windows,$(ALL_OS)), $(foreach arch, $(ALL_ARCH.windows), $(foreach osversion, ${ALL_OSVERSIONS.windows}, ${os}-${osversion}-${arch}))) +ALL_OS_ARCH = $(ALL_OS_ARCH.linux)$(ALL_OS_ARCH.windows) + +ALL_IMAGE_TAGS = $(IMAGE_TAGS) +ifeq ($(BUILDX_TAG_GCR), true) + ALL_IMAGE_TAGS += $(GCR_IMAGE_TAGS) +endif # set git sha and tree state GIT_SHA = $(shell git rev-parse HEAD) @@ -198,20 +222,29 @@ container: ifneq ($(BUILDX_ENABLED), true) $(error $(BUILDX_ERROR)) endif - @docker buildx rm velero-$(BIN)-builder || true - @docker buildx create --use --name=velero-$(BIN)-builder - $(MAKE) container-linux + -docker buildx rm velero-builder || true + @docker buildx create --use --name=velero-builder - for osversion in $(ALL_OSVERSIONS.windows); do \ - OSVERSION=$${osversion} $(MAKE) container-windows; \ + @for osarch in $(ALL_OS_ARCH); do \ + $(MAKE) container-$${osarch}; \ done +ifeq ($(BUILDX_PUSH), true) + @for tag in $(ALL_IMAGE_TAGS); do \ + IMAGE_TAG=$${tag} $(MAKE) push-manifest; \ + done +endif + +container-linux-%: + @BUILDX_ARCH=$* $(MAKE) container-linux + container-linux: + @echo "building container: $(IMAGE):$(VERSION)-linux-$(BUILDX_ARCH)" + @docker buildx build --pull \ --output=type=$(BUILDX_OUTPUT_TYPE) \ - --platform $(BUILDX_PLATFORMS) \ - $(addprefix -t , $(IMAGE_TAGS)) \ - $(addprefix -t , $(GCR_IMAGE_TAGS)) \ + --platform="linux/$(BUILDX_ARCH)" \ + $(addprefix -t , $(addsuffix "-linux-$(BUILDX_ARCH)",$(ALL_IMAGE_TAGS))) \ --build-arg=GOPROXY=$(GOPROXY) \ --build-arg=PKG=$(PKG) \ --build-arg=BIN=$(BIN) \ @@ -220,25 +253,54 @@ container-linux: --build-arg=GIT_TREE_STATE=$(GIT_TREE_STATE) \ --build-arg=REGISTRY=$(REGISTRY) \ --build-arg=RESTIC_VERSION=$(RESTIC_VERSION) \ + --provenance=false \ + --sbom=false \ -f $(VELERO_DOCKERFILE) . + @echo "built container: $(IMAGE):$(VERSION)-linux-$(BUILDX_ARCH)" + +container-windows-%: + @BUILDX_OSVERSION=$(firstword $(subst -, ,$*)) BUILDX_ARCH=$(lastword $(subst -, ,$*)) $(MAKE) container-windows + container-windows: + @echo "building container: $(IMAGE):$(VERSION)-windows-$(BUILDX_OSVERSION)-$(BUILDX_ARCH)" + @docker buildx build --pull \ --output=type=$(BUILDX_OUTPUT_TYPE) \ - --platform $(BUILDX_PLATFORMS) \ - $(addprefix -t , $(IMAGE_TAGS)) \ - $(addprefix -t , $(GCR_IMAGE_TAGS)) \ + --platform="windows/$(BUILDX_ARCH)" \ + $(addprefix -t , $(addsuffix "-windows-$(BUILDX_OSVERSION)-$(BUILDX_ARCH)",$(ALL_IMAGE_TAGS))) \ --build-arg=GOPROXY=$(GOPROXY) \ --build-arg=PKG=$(PKG) \ --build-arg=BIN=$(BIN) \ --build-arg=VERSION=$(VERSION) \ + --build-arg=OS_VERSION=$(BUILDX_OSVERSION) \ --build-arg=GIT_SHA=$(GIT_SHA) \ - --build-arg=GIT_TREE_STATE=$(GIT_TREE_STATE) \ + --build-arg=GIT_TREE_STATE=$(GIT_TREE_STATE) \ --build-arg=REGISTRY=$(REGISTRY) \ - --build-arg=RESTIC_VERSION=$(RESTIC_VERSION) \ - -f $(VELERO_DOCKERFILE) . + --provenance=false \ + --sbom=false \ + -f $(VELERO_DOCKERFILE_WINDOWS) . + + @echo "built container: $(IMAGE):$(VERSION)-windows-$(BUILDX_OSVERSION)-$(BUILDX_ARCH)" + +push-manifest: + @echo "building manifest: $(IMAGE_TAG) for $(foreach osarch, $(ALL_OS_ARCH), $(IMAGE_TAG)-${osarch})" + @docker manifest create --amend $(IMAGE_TAG) $(foreach osarch, $(ALL_OS_ARCH), $(IMAGE_TAG)-${osarch}) + + @set -x; \ + for arch in $(ALL_ARCH.windows); do \ + for osversion in $(ALL_OSVERSIONS.windows); do \ + BASEIMAGE=mcr.microsoft.com/windows/nanoserver:$${osversion}; \ + full_version=`docker manifest inspect $${BASEIMAGE} | jq -r '.manifests[0].platform["os.version"]'`; \ + docker manifest annotate --os windows --arch $${arch} --os-version $${full_version} $(IMAGE_TAG) $(IMAGE_TAG)-windows-$${osversion}-$${arch}; \ + done; \ + done + + @echo "pushing mainifest $(IMAGE_TAG)" + @docker manifest push --purge $(IMAGE_TAG) - @echo "container: $(IMAGE):$(VERSION)" + @echo "pushed mainifest $(IMAGE_TAG):" + @docker manifest inspect $(IMAGE_TAG) SKIP_TESTS ?= test: build-dirs From baf74d67a7c692926d2bec296d22ed4fab52366e Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Tue, 3 Dec 2024 13:35:04 +0800 Subject: [PATCH 3/4] build hybrid image Signed-off-by: Lyndon-Li --- .github/workflows/e2e-test-kind.yaml | 6 ++-- Dockerfile-Windows | 5 +--- Makefile | 34 +++++++++++----------- changelogs/unreleased/8476-Lyndon-Li | 1 + design/multiple-arch-build-with-windows.md | 8 ++--- hack/docker-push.sh | 20 ++++++++----- 6 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 changelogs/unreleased/8476-Lyndon-Li diff --git a/.github/workflows/e2e-test-kind.yaml b/.github/workflows/e2e-test-kind.yaml index 6df789f894..166b88fa23 100644 --- a/.github/workflows/e2e-test-kind.yaml +++ b/.github/workflows/e2e-test-kind.yaml @@ -42,8 +42,8 @@ jobs: - name: Build Velero Image if: steps.image-cache.outputs.cache-hit != 'true' run: | - IMAGE=velero VERSION=pr-test make container - docker save velero:pr-test -o ./velero.tar + IMAGE=velero VERSION=pr-test BUILD_OUTPUT_TYPE=docker make container + docker save velero:pr-test-linux-amd64 -o ./velero.tar # Create json of k8s versions to test # from guide: https://stackoverflow.com/a/65094398/4590470 setup-test-matrix: @@ -130,7 +130,7 @@ jobs: ADDITIONAL_BSL_CONFIG=region=minio,s3ForcePathStyle="true",s3Url=http://$(hostname -i):9000 \ ADDITIONAL_CREDS_FILE=/tmp/credential \ ADDITIONAL_BSL_BUCKET=additional-bucket \ - VELERO_IMAGE=velero:pr-test \ + VELERO_IMAGE=velero:pr-test-linux-amd64 \ GINKGO_LABELS="${{ matrix.labels }}" \ make -C test/ run-e2e timeout-minutes: 30 diff --git a/Dockerfile-Windows b/Dockerfile-Windows index 3bfcf222b8..ec60e1e8b1 100644 --- a/Dockerfile-Windows +++ b/Dockerfile-Windows @@ -1,4 +1,4 @@ -# Copyright 2020 the Velero contributors. +# Copyright the Velero contributors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,8 +38,6 @@ ENV CGO_ENABLED=0 \ WORKDIR /go/src/github.com/vmware-tanzu/velero -RUN apt-get update && apt-get install -y jq - COPY . /go/src/github.com/vmware-tanzu/velero RUN mkdir -p /output/usr/bin && \ @@ -52,7 +50,6 @@ RUN mkdir -p /output/usr/bin && \ # Velero image packing section FROM mcr.microsoft.com/windows/nanoserver:${OS_VERSION} -ENTRYPOINT [ "velero.exe" ] COPY --from=velero-builder /output / USER ContainerUser \ No newline at end of file diff --git a/Makefile b/Makefile index b30b985a1b..2d3aa6703b 100644 --- a/Makefile +++ b/Makefile @@ -101,30 +101,28 @@ comma=, RESTIC_VERSION ?= 0.15.0 CLI_PLATFORMS ?= linux-amd64 linux-arm linux-arm64 darwin-amd64 darwin-arm64 windows-amd64 linux-ppc64le -BUILDX_PUSH ?= false -BUILDX_BUILD_OS ?= linux -BUILDX_BUILD_ARCH ?= amd64 -BUILDX_TAG_GCR ?= false -BUILDX_WINDOWS_VERSION ?= ltsc2022 +BUILD_OUTPUT_TYPE ?= docker +BUILD_OS ?= linux +BUILD_ARCH ?= amd64 +BUILD_TAG_GCR ?= false +BUILD_WINDOWS_VERSION ?= ltsc2022 -ifneq ($(BUILDX_PUSH), true) +ifeq ($(BUILD_OUTPUT_TYPE), docker) ALL_OS = linux ALL_ARCH.linux = $(word 2, $(subst -, ,$(shell go env GOOS)-$(shell go env GOARCH))) - BUILDX_OUTPUT_TYPE = docker else - ALL_OS = $(subst $(comma), ,$(BUILDX_BUILD_OS)) - ALL_ARCH.linux = $(subst $(comma), ,$(BUILDX_BUILD_ARCH)) - BUILDX_OUTPUT_TYPE = registry + ALL_OS = $(subst $(comma), ,$(BUILD_OS)) + ALL_ARCH.linux = $(subst $(comma), ,$(BUILD_ARCH)) endif ALL_ARCH.windows = $(if $(filter windows,$(ALL_OS)),amd64,) -ALL_OSVERSIONS.windows = $(if $(filter windows,$(ALL_OS)),$(BUILDX_WINDOWS_VERSION),) +ALL_OSVERSIONS.windows = $(if $(filter windows,$(ALL_OS)),$(BUILD_WINDOWS_VERSION),) ALL_OS_ARCH.linux = $(foreach os, $(filter linux,$(ALL_OS)), $(foreach arch, ${ALL_ARCH.linux}, ${os}-$(arch))) ALL_OS_ARCH.windows = $(foreach os, $(filter windows,$(ALL_OS)), $(foreach arch, $(ALL_ARCH.windows), $(foreach osversion, ${ALL_OSVERSIONS.windows}, ${os}-${osversion}-${arch}))) ALL_OS_ARCH = $(ALL_OS_ARCH.linux)$(ALL_OS_ARCH.windows) ALL_IMAGE_TAGS = $(IMAGE_TAGS) -ifeq ($(BUILDX_TAG_GCR), true) +ifeq ($(BUILD_TAG_GCR), true) ALL_IMAGE_TAGS += $(GCR_IMAGE_TAGS) endif @@ -225,11 +223,13 @@ endif -docker buildx rm velero-builder || true @docker buildx create --use --name=velero-builder + @mkdir -p _output + @for osarch in $(ALL_OS_ARCH); do \ $(MAKE) container-$${osarch}; \ done -ifeq ($(BUILDX_PUSH), true) +ifeq ($(BUILD_OUTPUT_TYPE), registry) @for tag in $(ALL_IMAGE_TAGS); do \ IMAGE_TAG=$${tag} $(MAKE) push-manifest; \ done @@ -242,7 +242,7 @@ container-linux: @echo "building container: $(IMAGE):$(VERSION)-linux-$(BUILDX_ARCH)" @docker buildx build --pull \ - --output=type=$(BUILDX_OUTPUT_TYPE) \ + --output="type=$(BUILD_OUTPUT_TYPE)$(if $(findstring tar, $(BUILD_OUTPUT_TYPE)),$(comma)dest=_output/$(BIN)-$(VERSION)-linux-$(BUILDX_ARCH).tar,)" \ --platform="linux/$(BUILDX_ARCH)" \ $(addprefix -t , $(addsuffix "-linux-$(BUILDX_ARCH)",$(ALL_IMAGE_TAGS))) \ --build-arg=GOPROXY=$(GOPROXY) \ @@ -266,7 +266,7 @@ container-windows: @echo "building container: $(IMAGE):$(VERSION)-windows-$(BUILDX_OSVERSION)-$(BUILDX_ARCH)" @docker buildx build --pull \ - --output=type=$(BUILDX_OUTPUT_TYPE) \ + --output="type=$(BUILD_OUTPUT_TYPE)$(if $(findstring tar, $(BUILD_OUTPUT_TYPE)),$(comma)dest=_output/$(BIN)-$(VERSION)-windows-$(BUILDX_OSVERSION)-$(BUILDX_ARCH).tar,)" \ --platform="windows/$(BUILDX_ARCH)" \ $(addprefix -t , $(addsuffix "-windows-$(BUILDX_OSVERSION)-$(BUILDX_ARCH)",$(ALL_IMAGE_TAGS))) \ --build-arg=GOPROXY=$(GOPROXY) \ @@ -296,10 +296,10 @@ push-manifest: done; \ done - @echo "pushing mainifest $(IMAGE_TAG)" + @echo "pushing manifest $(IMAGE_TAG)" @docker manifest push --purge $(IMAGE_TAG) - @echo "pushed mainifest $(IMAGE_TAG):" + @echo "pushed manifest $(IMAGE_TAG):" @docker manifest inspect $(IMAGE_TAG) SKIP_TESTS ?= diff --git a/changelogs/unreleased/8476-Lyndon-Li b/changelogs/unreleased/8476-Lyndon-Li new file mode 100644 index 0000000000..484465fb86 --- /dev/null +++ b/changelogs/unreleased/8476-Lyndon-Li @@ -0,0 +1 @@ +Fix issue #8415, implement multi-arch build and Windows build \ No newline at end of file diff --git a/design/multiple-arch-build-with-windows.md b/design/multiple-arch-build-with-windows.md index a6bdc381f2..5ebb435d42 100644 --- a/design/multiple-arch-build-with-windows.md +++ b/design/multiple-arch-build-with-windows.md @@ -76,7 +76,7 @@ The built image could be listed by `docker image ls`. **Local build for linux-amd64 and windows-amd64 to tar** ``` -BUILDX_OUTPUT_TYPE=tar BUILD_OS=linux,windows make container +BUILD_OUTPUT_TYPE=tar BUILD_OS=linux,windows make container ``` Under `_output` directory, below files are generated: ``` @@ -86,7 +86,7 @@ velero-main-windows-ltsc2022-amd64.tar **Local build for linux-amd64, linux-arm64 and windows-amd64 to tar** ``` -BUILDX_OUTPUT_TYPE=tar BUILD_OS=linux,windows BUILD_ARCH=amd64,arm64 make container +BUILD_OUTPUT_TYPE=tar BUILD_OS=linux,windows BUILD_ARCH=amd64,arm64 make container ``` Under `_output` directory, below files are generated: ``` @@ -98,7 +98,7 @@ velero-main-windows-ltsc2022-amd64.tar **Push build for linux-amd64 and windows-amd64** Prerequisite: login to registry, e.g., through `docker login` ``` -BUILDX_OUTPUT_TYPE=registry REGISTRY= BUILD_OS=linux,windows make container +BUILD_OUTPUT_TYPE=registry REGISTRY= BUILD_OS=linux,windows make container ``` Nothing is available locally, in the registry 3 tags are available: ``` @@ -110,7 +110,7 @@ velero/velero:main-linux-amd64 **Push build for linux-amd64, linux-arm64 and windows-amd64** Prerequisite: login to registry, e.g., through `docker login` ``` -BUILDX_OUTPUT_TYPE=registry REGISTRY= BUILD_OS=linux,windows BUILD_ARCH=amd64,arm64 make container +BUILD_OUTPUT_TYPE=registry REGISTRY= BUILD_OS=linux,windows BUILD_ARCH=amd64,arm64 make container ``` Nothing is available locally, in the registry 4 tags are available: ``` diff --git a/hack/docker-push.sh b/hack/docker-push.sh index e503358c9f..b54f01038e 100755 --- a/hack/docker-push.sh +++ b/hack/docker-push.sh @@ -63,7 +63,7 @@ fi if [[ -z $BRANCH && -z $TAG ]]; then echo "Test Velero container build without pushing, when Dockerfile is changed by PR." BRANCH="${GITHUB_BASE_REF}-container" - OUTPUT_TYPE="local,dest=." + OUTPUT_TYPE="tar" else OUTPUT_TYPE="registry" fi @@ -88,8 +88,12 @@ else fi fi -if [[ -z "$BUILDX_PLATFORMS" ]]; then - BUILDX_PLATFORMS="linux/amd64,linux/arm64" +if [[ -z "$BUILD_OS" ]]; then + BUILD_OS="linux,windows" +fi + +if [[ -z "$BUILD_ARCH" ]]; then + BUILD_ARCH="amd64,arm64" fi # Debugging info @@ -98,13 +102,15 @@ echo "BRANCH: $BRANCH" echo "TAG: $TAG" echo "TAG_LATEST: $TAG_LATEST" echo "VERSION: $VERSION" -echo "BUILDX_PLATFORMS: $BUILDX_PLATFORMS" +echo "BUILD_OS: $BUILD_OS" +echo "BUILD_ARCH: $BUILD_ARCH" echo "Building and pushing container images." VERSION="$VERSION" \ TAG_LATEST="$TAG_LATEST" \ -BUILDX_PLATFORMS="$BUILDX_PLATFORMS" \ -BUILDX_OUTPUT_TYPE=$OUTPUT_TYPE \ -make all-containers +BUILD_OS="$BUILD_OS" \ +BUILD_ARCH="$BUILD_ARCH" \ +BUILD_OUTPUT_TYPE=$OUTPUT_TYPE \ +make all-containers \ No newline at end of file From ed9af610e5bdc254bc5a822c86d03ddfd7b17761 Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Fri, 6 Dec 2024 14:48:47 +0800 Subject: [PATCH 4/4] support specified buildx instance Signed-off-by: Lyndon-Li --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 2d3aa6703b..67e528bf8e 100644 --- a/Makefile +++ b/Makefile @@ -220,8 +220,15 @@ container: ifneq ($(BUILDX_ENABLED), true) $(error $(BUILDX_ERROR)) endif + +ifeq ($(BUILDX_INSTANCE),) + @echo creating a buildx instance -docker buildx rm velero-builder || true @docker buildx create --use --name=velero-builder +else + @echo using a specified buildx instance $(BUILDX_INSTANCE) + @docker buildx use $(BUILDX_INSTANCE) +endif @mkdir -p _output