diff --git a/controller/Containerfile b/controller/Containerfile index d017e8718..331a8530a 100644 --- a/controller/Containerfile +++ b/controller/Containerfile @@ -1,5 +1,7 @@ # Build the manager binary -FROM registry.access.redhat.com/ubi10/go-toolset:1.26.3 AS builder +# Use --platform=$BUILDPLATFORM to run the Go compiler natively on the build host +# instead of under QEMU emulation. Go cross-compiles via GOOS/GOARCH (CGO_ENABLED=0). +FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi10/go-toolset:1.26.3 AS builder ARG TARGETOS ARG TARGETARCH ARG GIT_VERSION=unknown diff --git a/controller/Containerfile.operator b/controller/Containerfile.operator index 0a958aaa9..d9a5101cb 100644 --- a/controller/Containerfile.operator +++ b/controller/Containerfile.operator @@ -1,5 +1,7 @@ # Build the manager binary -FROM registry.access.redhat.com/ubi10/go-toolset:1.26.3 AS builder +# Use --platform=$BUILDPLATFORM to run the Go compiler natively on the build host +# instead of under QEMU emulation. Go cross-compiles via GOOS/GOARCH (CGO_ENABLED=0). +FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi10/go-toolset:1.26.3 AS builder ARG TARGETOS ARG TARGETARCH ARG GIT_VERSION=unknown diff --git a/controller/Makefile b/controller/Makefile index 54a170839..965f31761 100644 --- a/controller/Makefile +++ b/controller/Makefile @@ -141,8 +141,6 @@ docker-push: ## Push docker image with the manager. PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx docker-buildx: ## Build and push docker image for the manager for cross-platform support - # copy existing Containerfile and insert --platform=${BUILDPLATFORM} into Containerfile.cross, and preserve the original Containerfile - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Containerfile > Containerfile.cross - $(CONTAINER_TOOL) buildx create --name jumpstarter-controller-builder $(CONTAINER_TOOL) buildx use jumpstarter-controller-builder - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) \ @@ -151,9 +149,8 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform --build-arg BUILD_DATE=$(BUILD_DATE) \ --tag ${DOCKER_REPO}:${DOCKER_TAG} \ --tag ${DOCKER_REPO}:latest \ - -f Containerfile.cross . + -f Containerfile . - $(CONTAINER_TOOL) buildx rm jumpstarter-controller-builder - rm Containerfile.cross .PHONY: build-installer build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment. diff --git a/controller/deploy/operator/Makefile b/controller/deploy/operator/Makefile index 9448672e1..89fef9e58 100644 --- a/controller/deploy/operator/Makefile +++ b/controller/deploy/operator/Makefile @@ -190,17 +190,14 @@ docker-push: ## Push docker image with the manager. PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx docker-buildx: ## Build and push docker image for the manager for cross-platform support - # copy existing Containerfile and insert --platform=${BUILDPLATFORM} into Containerfile.cross, and preserve the original Containerfile - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' ../../Containerfile.operator > ../../Containerfile.operator.cross - $(CONTAINER_TOOL) buildx create --name jumpstarter-operator-builder $(CONTAINER_TOOL) buildx use jumpstarter-operator-builder - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) \ --build-arg GIT_VERSION=$(GIT_VERSION) \ --build-arg GIT_COMMIT=$(GIT_COMMIT) \ --build-arg BUILD_DATE=$(BUILD_DATE) \ - --tag ${IMG} -f ../../Containerfile.operator.cross ../../ + --tag ${IMG} -f ../../Containerfile.operator ../../ - $(CONTAINER_TOOL) buildx rm jumpstarter-operator-builder - rm ../../Containerfile.operator.cross .PHONY: build-installer build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.