diff --git a/Makefile b/Makefile index 38c5705a..5f3d6f39 100644 --- a/Makefile +++ b/Makefile @@ -19,18 +19,22 @@ LABELLER_TAG ?= labeller-$(IMAGE_VERSION) UBI_DEVICE_PLUGIN_TAG ?= rhubi-$(IMAGE_VERSION) UBI_LABELLER_TAG ?= labeller-rhubi-$(IMAGE_VERSION) +# Multi-architecture support +PLATFORMS ?= linux/amd64,linux/ppc64le + # Output directory for tar.gz files OUTPUT_DIR ?= ./dist TAR_DIR ?= $(OUTPUT_DIR)/tarballs .PHONY: all build-all save-all clean help .PHONY: build-device-plugin build-labeller build-ubi-device-plugin build-ubi-labeller +.PHONY: build-device-plugin-local build-labeller-local build-ubi-device-plugin-local build-ubi-labeller-local .PHONY: save-device-plugin save-labeller save-ubi-device-plugin save-ubi-labeller # Default target all: build-all save-all -# Build all images +# Build all images (multi-arch with push) build-all: build-device-plugin build-labeller build-ubi-device-plugin build-ubi-labeller @echo "All images built successfully" @@ -38,28 +42,52 @@ build-all: build-device-plugin build-labeller build-ubi-device-plugin build-ubi- save-all: save-device-plugin save-labeller save-ubi-device-plugin save-ubi-labeller @echo "All images saved to $(TAR_DIR)/" -# Build Alpine-based device plugin image +# Build Alpine-based device plugin image (multi-arch with push) build-device-plugin: - @echo "Building Alpine-based device plugin image..." - docker build -t $(IMAGE_REPO):$(DEVICE_PLUGIN_TAG) -f Dockerfile . - @echo "Built: $(IMAGE_REPO):$(DEVICE_PLUGIN_TAG)" + @echo "Building multi-arch Alpine-based device plugin image..." + docker buildx build --platform $(PLATFORMS) -t $(IMAGE_REPO):$(DEVICE_PLUGIN_TAG) -f Dockerfile --push . + @echo "Built and pushed: $(IMAGE_REPO):$(DEVICE_PLUGIN_TAG)" -# Build Alpine-based node labeller image +# Build Alpine-based node labeller image (multi-arch with push) build-labeller: - @echo "Building Alpine-based node labeller image..." - docker build -t $(IMAGE_REPO):$(LABELLER_TAG) -f labeller.Dockerfile . - @echo "Built: $(IMAGE_REPO):$(LABELLER_TAG)" + @echo "Building multi-arch Alpine-based node labeller image..." + docker buildx build --platform $(PLATFORMS) -t $(IMAGE_REPO):$(LABELLER_TAG) -f labeller.Dockerfile --push . + @echo "Built and pushed: $(IMAGE_REPO):$(LABELLER_TAG)" -# Build UBI-based device plugin image +# Build UBI-based device plugin image (multi-arch with push) build-ubi-device-plugin: - @echo "Building UBI-based device plugin image..." - docker build -t $(IMAGE_REPO):$(UBI_DEVICE_PLUGIN_TAG) -f ubi-dp.Dockerfile . - @echo "Built: $(IMAGE_REPO):$(UBI_DEVICE_PLUGIN_TAG)" + @echo "Building multi-arch UBI-based device plugin image..." + docker buildx build --platform $(PLATFORMS) -t $(IMAGE_REPO):$(UBI_DEVICE_PLUGIN_TAG) -f ubi-dp.Dockerfile --push . + @echo "Built and pushed: $(IMAGE_REPO):$(UBI_DEVICE_PLUGIN_TAG)" -# Build UBI-based node labeller image +# Build UBI-based node labeller image (multi-arch with push) build-ubi-labeller: - @echo "Building UBI-based node labeller image..." - docker build -t $(IMAGE_REPO):$(UBI_LABELLER_TAG) -f ubi-labeller.Dockerfile . + @echo "Building multi-arch UBI-based node labeller image..." + docker buildx build --platform $(PLATFORMS) -t $(IMAGE_REPO):$(UBI_LABELLER_TAG) -f ubi-labeller.Dockerfile --push . + @echo "Built and pushed: $(IMAGE_REPO):$(UBI_LABELLER_TAG)" + +# Build Alpine-based device plugin image (local, single-arch, no push) +build-device-plugin-local: + @echo "Building local Alpine-based device plugin image..." + DOCKER_BUILDKIT=1 docker build -t $(IMAGE_REPO):$(DEVICE_PLUGIN_TAG) -f Dockerfile . + @echo "Built: $(IMAGE_REPO):$(DEVICE_PLUGIN_TAG)" + +# Build Alpine-based node labeller image (local, single-arch, no push) +build-labeller-local: + @echo "Building local Alpine-based node labeller image..." + DOCKER_BUILDKIT=1 docker build -t $(IMAGE_REPO):$(LABELLER_TAG) -f labeller.Dockerfile . + @echo "Built: $(IMAGE_REPO):$(LABELLER_TAG)" + +# Build UBI-based device plugin image (local, single-arch, no push) +build-ubi-device-plugin-local: + @echo "Building local UBI-based device plugin image..." + DOCKER_BUILDKIT=1 docker build -t $(IMAGE_REPO):$(UBI_DEVICE_PLUGIN_TAG) -f ubi-dp.Dockerfile . + @echo "Built: $(IMAGE_REPO):$(UBI_DEVICE_PLUGIN_TAG)" + +# Build UBI-based node labeller image (local, single-arch, no push) +build-ubi-labeller-local: + @echo "Building local UBI-based node labeller image..." + DOCKER_BUILDKIT=1 docker build -t $(IMAGE_REPO):$(UBI_LABELLER_TAG) -f ubi-labeller.Dockerfile . @echo "Built: $(IMAGE_REPO):$(UBI_LABELLER_TAG)" # Save Alpine device plugin image to tar.gz diff --git a/ubi-dp.Dockerfile b/ubi-dp.Dockerfile index dca62a2b..349960d5 100644 --- a/ubi-dp.Dockerfile +++ b/ubi-dp.Dockerfile @@ -12,16 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. FROM registry.access.redhat.com/ubi9/ubi:latest as builder +ARG TARGETARCH USER root -RUN dnf install -y 'dnf-command(config-manager)' && \ - dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/ && \ - dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/ && \ +RUN CENTOS_ARCH=${TARGETARCH}; \ + if [ "$CENTOS_ARCH" = "amd64" ]; then CENTOS_ARCH="x86_64"; fi; \ + dnf install -y 'dnf-command(config-manager)' && \ + dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/BaseOS/${CENTOS_ARCH}/os/ && \ + dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/AppStream/${CENTOS_ARCH}/os/ && \ rpm --import https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official && \ dnf install git pkgconfig gcc gcc-c++ make glibc-devel binutils libdrm-devel hwloc-devel wget tar gzip -y && \ dnf clean all -RUN wget https://golang.org/dl/go1.23.3.linux-amd64.tar.gz && \ - tar -C /usr/local -xzf go1.23.3.linux-amd64.tar.gz && \ - rm go1.23.3.linux-amd64.tar.gz +RUN wget https://golang.org/dl/go1.23.3.linux-${TARGETARCH}.tar.gz && \ + tar -C /usr/local -xzf go1.23.3.linux-${TARGETARCH}.tar.gz && \ + rm go1.23.3.linux-${TARGETARCH}.tar.gz ENV PATH="/usr/local/go/bin:${PATH}" ENV GOPATH="/go" RUN mkdir -p /go/src/github.com/ROCm/k8s-device-plugin @@ -40,12 +43,15 @@ LABEL \ release="latest" \ summary="The AMD K8s Device Plugin enables the registration of AMD GPUs in your Kubernetes cluster for compute workloads." \ description="The AMD K8s Device Plugin enables the registration of AMD GPUs in your Kubernetes cluster for compute workloads. With the appropriate hardware and this plugin deployed in your Kubernetes cluster, you will be able to run jobs that require AMD GPU." -RUN mkdir -p /licenses && \ +ARG TARGETARCH +RUN CENTOS_ARCH=${TARGETARCH}; \ + if [ "$CENTOS_ARCH" = "amd64" ]; then CENTOS_ARCH="x86_64"; fi; \ + mkdir -p /licenses && \ dnf install -y ca-certificates libdrm && \ rpm --import https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official && \ dnf install -y 'dnf-command(config-manager)' && \ - dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/ && \ - dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/ && \ + dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/BaseOS/${CENTOS_ARCH}/os/ && \ + dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/AppStream/${CENTOS_ARCH}/os/ && \ dnf install -y hwloc && \ dnf clean all ADD ./LICENSE /licenses/LICENSE diff --git a/ubi-labeller.Dockerfile b/ubi-labeller.Dockerfile index 6d1cfee4..53135222 100644 --- a/ubi-labeller.Dockerfile +++ b/ubi-labeller.Dockerfile @@ -12,16 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. FROM registry.access.redhat.com/ubi9/ubi:latest as builder +ARG TARGETARCH USER root -RUN dnf install -y 'dnf-command(config-manager)' && \ - dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/ && \ - dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/ && \ +RUN CENTOS_ARCH=${TARGETARCH}; \ + if [ "$CENTOS_ARCH" = "amd64" ]; then CENTOS_ARCH="x86_64"; fi; \ + dnf install -y 'dnf-command(config-manager)' && \ + dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/BaseOS/${CENTOS_ARCH}/os/ && \ + dnf config-manager --add-repo=https://mirror.stream.centos.org/9-stream/AppStream/${CENTOS_ARCH}/os/ && \ rpm --import https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official && \ dnf install git pkgconfig gcc gcc-c++ make glibc-devel binutils libdrm-devel wget tar gzip -y && \ dnf clean all -RUN wget https://golang.org/dl/go1.23.3.linux-amd64.tar.gz && \ - tar -C /usr/local -xzf go1.23.3.linux-amd64.tar.gz && \ - rm go1.23.3.linux-amd64.tar.gz +RUN wget https://golang.org/dl/go1.23.3.linux-${TARGETARCH}.tar.gz && \ + tar -C /usr/local -xzf go1.23.3.linux-${TARGETARCH}.tar.gz && \ + rm go1.23.3.linux-${TARGETARCH}.tar.gz ENV PATH="/usr/local/go/bin:${PATH}" ENV GOPATH="/go" RUN mkdir -p /go/src/github.com/ROCm/k8s-device-plugin