diff --git a/Dockerfile b/Dockerfile index 9a323ef4a..91282dd98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,10 @@ # Build the manager binary -FROM golang:1.21.1 as builder +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.21.1 as builder + +ARG TARGETPLATFORM +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH WORKDIR /workspace # Copy the Go Modules manifests @@ -18,11 +23,11 @@ COPY tools/ tools/ COPY hack hack/ # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM registry.access.redhat.com/ubi8/ubi:latest +FROM --platform=${TARGETPLATFORM:-linux/amd64} registry.access.redhat.com/ubi8/ubi:latest ENV OPERATOR=/manager \ USER_UID=1001 \ diff --git a/Makefile b/Makefile index dd59513ae..17d1515de 100644 --- a/Makefile +++ b/Makefile @@ -9,11 +9,11 @@ VERSION ?= 2.2.1 SPLUNK_ENTERPRISE_IMAGE ?= "docker.io/splunk/splunk:edge" # WATCH_NAMESPACE defines if its clusterwide operator or namespace specific -# by default we leave it as clusterwide if it has to be namespace specific, +# by default we leave it as clusterwide if it has to be namespace specific, # add namespace to this WATCH_NAMESPACE ?= "" -# NAMESPACE defines default namespace where operator will be installed +# NAMESPACE defines default namespace where operator will be installed NAMESPACE ?= "splunk-operator" # CHANNELS define the bundle channels used in the bundle. @@ -25,6 +25,8 @@ ifneq ($(origin CHANNELS), undefined) BUNDLE_CHANNELS := --channels=$(CHANNELS) endif +export DOCKER_CLI_EXPERIMENTAL=enabled + # DEFAULT_CHANNEL defines the default channel used in the bundle. # Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable") # To re-generate a bundle for any other default channel without changing the default setup, you can: @@ -153,12 +155,12 @@ 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 + # sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - 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} . - docker buildx rm project-v3-builder - rm Dockerfile.cross + # rm Dockerfile.cross ##@ Deployment