diff --git a/Makefile b/Makefile index cac48a6fd..15500501c 100644 --- a/Makefile +++ b/Makefile @@ -13,13 +13,16 @@ OPERATOR_IMAGE ?= cluster-network-addons-operator REGISTRY_IMAGE ?= cluster-network-addons-registry export OCI_BIN ?= $(shell if podman ps >/dev/null 2>&1; then echo podman; elif docker ps >/dev/null 2>&1; then echo docker; fi) TLS_SETTING := $(if $(filter $(OCI_BIN),podman),--tls-verify=false,) -PLATFORMS ?= linux/amd64 +PLATFORM_LIST ?= linux/amd64,linux/s390x,linux/arm64 +ARCH := $(shell uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') +PLATFORMS ?= linux/${ARCH} +PLATFORMS := $(if $(filter all,$(PLATFORMS)),$(PLATFORM_LIST),$(PLATFORMS)) # Set the platforms for building a multi-platform supported image. # Example: # PLATFORMS ?= linux/amd64,linux/arm64,linux/s390x # Alternatively, you can export the PLATFORMS variable like this: # export PLATFORMS=linux/arm64,linux/s390x,linux/amd64 -ARCH := $(shell uname -m | sed 's/x86_64/amd64/') +# or export PLATFORMS=all to automatically include all supported platforms. DOCKER_BUILDER ?= cnao-docker-builder OPERATOR_IMAGE_TAGGED := $(IMAGE_REGISTRY)/$(OPERATOR_IMAGE):$(IMAGE_TAG) diff --git a/hack/build-operator-docker.sh b/hack/build-operator-docker.sh index 09fa91a3f..4a6684312 100755 --- a/hack/build-operator-docker.sh +++ b/hack/build-operator-docker.sh @@ -14,4 +14,5 @@ if [ ${#PLATFORM_LIST[@]} -eq 1 ]; then else ./hack/init-buildx.sh "$DOCKER_BUILDER" docker buildx build --platform "$PLATFORMS" $BUILD_ARGS + docker buildx rm "$DOCKER_BUILDER" 2>/dev/null || echo "Builder ${DOCKER_BUILDER} not found or already removed, skipping." fi diff --git a/hack/build-operator-podman.sh b/hack/build-operator-podman.sh index b0fd3740e..c47f64f9f 100755 --- a/hack/build-operator-podman.sh +++ b/hack/build-operator-podman.sh @@ -8,14 +8,13 @@ fi IFS=',' read -r -a PLATFORM_LIST <<< "$PLATFORMS" # Remove any existing manifest and image -podman manifest rm "${OPERATOR_IMAGE_TAGGED}" || true -podman rmi "${OPERATOR_IMAGE_TAGGED}" || true +podman manifest rm "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null || true +podman rmi "${OPERATOR_IMAGE_TAGGED}" 2>/dev/null || true podman manifest create "${OPERATOR_IMAGE_TAGGED}" for platform in "${PLATFORM_LIST[@]}"; do podman build \ - --no-cache \ --build-arg BUILD_ARCH="$ARCH" \ --platform "$platform" \ --manifest "${OPERATOR_IMAGE_TAGGED}" \ diff --git a/hack/init-buildx.sh b/hack/init-buildx.sh index fd444a201..bff7ab0be 100755 --- a/hack/init-buildx.sh +++ b/hack/init-buildx.sh @@ -6,7 +6,8 @@ check_buildx() { if ! docker buildx > /dev/null 2>&1; then mkdir -p ~/.docker/cli-plugins BUILDX_VERSION=$(curl -s https://api.github.com/repos/docker/buildx/releases/latest | jq -r .tag_name) - curl -L https://github.com/docker/buildx/releases/download/"${BUILDX_VERSION}"/buildx-"${BUILDX_VERSION}".linux-amd64 --output ~/.docker/cli-plugins/docker-buildx + ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') + curl -L https://github.com/docker/buildx/releases/download/"${BUILDX_VERSION}"/buildx-"${BUILDX_VERSION}".linux-"${ARCH}" --output ~/.docker/cli-plugins/docker-buildx chmod a+x ~/.docker/cli-plugins/docker-buildx fi } @@ -20,7 +21,7 @@ create_or_use_buildx_builder() { check_buildx - current_builder="$(docker buildx inspect "${builder_name}")" + current_builder="$(docker buildx inspect "${builder_name}" 2>/dev/null)" || echo "Builder '${builder_name}' not found" if ! grep -q "^Driver: docker$" <<<"${current_builder}" && \ grep -q "linux/amd64" <<<"${current_builder}" && \