From 872164516b44c0586407097da089241c9d8d6b75 Mon Sep 17 00:00:00 2001 From: kurokobo Date: Tue, 23 Jan 2024 01:56:48 +0900 Subject: [PATCH] fix: fix an issue that multi-arch images cannot be built from the project makefile (#6661) Signed-off-by: kurokobo <2920259+kurokobo@users.noreply.github.com> --- .../fragments/helm-fix-docker-buildx.yaml | 41 +++++++++++++++++++ .../scaffolds/internal/templates/makefile.go | 7 +--- testdata/helm/memcached-operator/Makefile | 7 +--- 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 changelog/fragments/helm-fix-docker-buildx.yaml diff --git a/changelog/fragments/helm-fix-docker-buildx.yaml b/changelog/fragments/helm-fix-docker-buildx.yaml new file mode 100644 index 00000000000..1825dfc9b1f --- /dev/null +++ b/changelog/fragments/helm-fix-docker-buildx.yaml @@ -0,0 +1,41 @@ +# entries is a list of entries to include in +# release notes and/or the migration guide +entries: + - description: > + (helm/v1) Fix an issue that multi-arch images cannot be built from the project Makefile. + + # kind is one of: + # - addition + # - change + # - deprecation + # - removal + # - bugfix + kind: "bugfix" + + # Is this a breaking change? + breaking: false + + # NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS + # FILE FOR A PREVIOUSLY MERGED PULL_REQUEST! + # + # The generator auto-detects the PR number from the commit + # message in which this file was originally added. + # + # What is the pull request number (without the "#")? + # pull_request_override: 0 + + + # Migration can be defined to automatically add a section to + # the migration guide. This is required for breaking changes. + migration: + header: To fix multi-arch build, replace docker-buildx target in project Makefile + body: | + In the project `Makefile`, replace existing `docker-buildx` target with following definition. + + ```make + docker-buildx: ## Build and push docker image for the manager for cross-platform support + - docker buildx create --name project-v3-builder + docker buildx use project-v3-builder + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile . + - docker buildx rm project-v3-builder + ``` diff --git a/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go b/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go index 631eb32f33d..dccaf36a5a4 100644 --- a/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go +++ b/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go @@ -110,14 +110,11 @@ docker-push: ## Push docker image with the manager. # To properly provided solutions that supports more than one platform you should use this option. PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx -docker-buildx: test ## Build and push docker image for the manager for cross-platform support - # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross +docker-buildx: ## Build and push docker image for the manager for cross-platform support - docker buildx create --name project-v3-builder docker buildx use project-v3-builder - - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile . - docker buildx rm project-v3-builder - rm Dockerfile.cross ##@ Deployment diff --git a/testdata/helm/memcached-operator/Makefile b/testdata/helm/memcached-operator/Makefile index 7db73d291b4..e80bea1666c 100644 --- a/testdata/helm/memcached-operator/Makefile +++ b/testdata/helm/memcached-operator/Makefile @@ -95,14 +95,11 @@ docker-push: ## Push docker image with the manager. # To properly provided solutions that supports more than one platform you should use this option. PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx -docker-buildx: test ## Build and push docker image for the manager for cross-platform support - # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross +docker-buildx: ## Build and push docker image for the manager for cross-platform support - docker buildx create --name project-v3-builder docker buildx use project-v3-builder - - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile . - docker buildx rm project-v3-builder - rm Dockerfile.cross ##@ Deployment