diff --git a/Dockerfile b/Dockerfile index 2f66ca7..dbc6162 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,43 @@ -FROM golang:1.22.1 as common-builder +FROM --platform=$BUILDPLATFORM golang:1.22.1 as common-builder WORKDIR $GOPATH/src/github.com/run-ai/fake-gpu-operator COPY go.mod . COPY go.sum . RUN go mod download COPY Makefile . COPY internal/common ./internal/common +ARG TARGETOS TARGETARCH FROM common-builder as device-plugin-builder COPY ./cmd/device-plugin/ ./cmd/device-plugin/ COPY ./internal/deviceplugin/ ./internal/deviceplugin/ -RUN make build COMPONENT=device-plugin +RUN --mount=type=cache,target=/root/.cache/go-build make build OS=$TARGETOS ARCH=$TARGETARCH COMPONENT=device-plugin FROM common-builder as status-updater-builder COPY ./cmd/status-updater/ ./cmd/status-updater/ COPY ./internal/status-updater/ ./internal/status-updater/ -RUN --mount=type=cache,target=/root/.cache/go-build make build COMPONENT=status-updater +RUN --mount=type=cache,target=/root/.cache/go-build make build OS=$TARGETOS ARCH=$TARGETARCH COMPONENT=status-updater FROM common-builder as status-exporter-builder COPY ./cmd/status-exporter/ ./cmd/status-exporter/ COPY ./internal/ ./internal/ -RUN --mount=type=cache,target=/root/.cache/go-build make build COMPONENT=status-exporter +RUN --mount=type=cache,target=/root/.cache/go-build make build OS=$TARGETOS ARCH=$TARGETARCH COMPONENT=status-exporter FROM common-builder as topology-server-builder COPY ./cmd/topology-server/ ./cmd/topology-server/ -RUN --mount=type=cache,target=/root/.cache/go-build make build COMPONENT=topology-server +RUN --mount=type=cache,target=/root/.cache/go-build make build OS=$TARGETOS ARCH=$TARGETARCH COMPONENT=topology-server FROM common-builder as nvidia-smi-builder COPY ./cmd/nvidia-smi/ ./cmd/nvidia-smi/ -RUN make build COMPONENT=nvidia-smi - -FROM common-builder as preloader-builder -COPY ./cmd/preloader/ ./cmd/preloader/ -RUN make build-preloader +RUN --mount=type=cache,target=/root/.cache/go-build make build OS=$TARGETOS ARCH=$TARGETARCH COMPONENT=nvidia-smi FROM common-builder as mig-faker-builder COPY ./cmd/mig-faker/ ./cmd/mig-faker/ COPY ./internal/ ./internal/ -RUN --mount=type=cache,target=/root/.cache/go-build make build COMPONENT=mig-faker +RUN --mount=type=cache,target=/root/.cache/go-build make build OS=$TARGETOS ARCH=$TARGETARCH COMPONENT=mig-faker + +FROM common-builder as preloader-builder +COPY ./cmd/preloader/ ./cmd/preloader/ +RUN make build-preloader FROM jupyter/minimal-notebook as jupyter-notebook COPY --from=nvidia-smi-builder /go/src/github.com/run-ai/fake-gpu-operator/bin/nvidia-smi /bin/ diff --git a/Makefile b/Makefile index 9f19bb5..dcb22c3 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,11 @@ DOCKER_TAG=0.0.0-dev DOCKER_IMAGE_NAME=${DOCKER_REPO_FULL}:${DOCKER_TAG} NAMESPACE=gpu-operator +OS?=linux +ARCH?=amd64 + build: - env GOOS=linux GOARCH=amd64 go build -o ${BUILD_DIR}/ ./cmd/${COMPONENT} + env GOOS=${OS} GOARCH=${ARCH} go build -o ${BUILD_DIR}/ ./cmd/${COMPONENT} .PHONY: build build-preloader: @@ -21,7 +24,8 @@ clean: .PHONY: clean image: - DOCKER_BUILDKIT=1 docker build -t ${DOCKER_IMAGE_NAME} --target ${COMPONENT} . + docker buildx inspect fgo-multi-platform > /dev/null || docker buildx create --name=fgo-multi-platform + docker buildx --builder=fgo-multi-platform build -t ${DOCKER_IMAGE_NAME} --target ${COMPONENT} --platform linux/amd64,linux/arm64 . .PHONY: image images: