You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Specifying TARGETPLATFORM as --platform is default behavior of BuildKit, so we can remove whole sed command.
Also, since there is no test target by default, referring test causes error. We should remove test target from docker-buildx.
$ make docker-buildx IMG="example.com/nginx-operator:v0.0.1" PLATFORMS=linux/arm64,linux/amd64
make: *** No rule to make target 'test', needed by 'docker-buildx'. Stop.
Diff:
diff --git a/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go b/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go
index 631eb32f..dccaf36a 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
Applying above changes can build the images for multi-platforms:
Bug Report
What did you do?
make docker-buildx
What did you expect to see?
make docker-buildx
builds the images forlinux/amd64
andlinux/arm64
.What did you see instead? Under which circumstances?
make docker-buildx
builds the image forlinux/amd64
(the platform where themake
has been invoked) only.Environment
Operator type:
/language helm
Kubernetes cluster type:
$ operator-sdk version
$ go version
(if language is Go)$ kubectl version
Possible Solution
The current
docker-buildx
target inMakefile
for Helm-based operator adds--platform=${BUILDPLATFORM}
to the firstFROM
inDockerfile
:operator-sdk/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go
Lines 113 to 115 in ce3a767
This is a correct configuration for fast cross-compilable with multi-stage builds for Go-based operator, but Helm-based operator does not use multi-stage builds, so the first
FROM
image must be forTARGETPLATFORM
, instead ofBUILDPLATFORM
: https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/My suggested changes:
TARGETPLATFORM
as--platform
is default behavior of BuildKit, so we can remove wholesed
command.test
target by default, referringtest
causes error. We should removetest
target fromdocker-buildx
.Diff:
Applying above changes can build the images for multi-platforms:
Additional context
The same issue can be applied for Ansible plugin. It's already reported:
The text was updated successfully, but these errors were encountered: