diff --git a/.circleci/config.yml b/.circleci/config.yml index 867e75c..754d0cf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -78,18 +78,13 @@ jobs: - checkout - pre_docker_commands - run: - name: "Build Images" + name: "Build and Push Images" environment: CIRCLE_TAG: <> - command: | - DOCKER_REPO_BASE="gcr.io/run-ai-staging/fake-gpu-operator" - make images DOCKER_REPO_BASE=${DOCKER_REPO_BASE} DOCKER_TAG=${CIRCLE_TAG} - - run: - name: "Push to Google Cloud" command: | TAG=<> DOCKER_REPO_BASE="gcr.io/run-ai-staging/fake-gpu-operator" - make push-all DOCKER_REPO_BASE=${DOCKER_REPO_BASE} DOCKER_TAG=${TAG} + make images DOCKER_REPO_BASE=${DOCKER_REPO_BASE} DOCKER_TAG=${TAG} SHOULD_PUSH=true deploy_to_production: executor: runai-executor steps: @@ -102,8 +97,7 @@ jobs: command: | TAG=${CIRCLE_TAG/v/''} DOCKER_REPO_BASE="gcr.io/run-ai-staging/fake-gpu-operator" - make images DOCKER_REPO_BASE=${DOCKER_REPO_BASE} DOCKER_TAG=${TAG} - make push-all DOCKER_REPO_BASE=${DOCKER_REPO_BASE} DOCKER_TAG=${TAG} + make images DOCKER_REPO_BASE=${DOCKER_REPO_BASE} DOCKER_TAG=${TAG} SHOULD_PUSH=true chart_build_staging: working_directory: ~/go/src/github.com/run-ai/fake-gpu-operator docker: 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..151ca6c 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,16 @@ DOCKER_TAG=0.0.0-dev DOCKER_IMAGE_NAME=${DOCKER_REPO_FULL}:${DOCKER_TAG} NAMESPACE=gpu-operator +SHOULD_PUSH?=false +DOCKER_BUILDX_PUSH_FLAG=$(if $(filter true,$(SHOULD_PUSH)),--push,) +DOCKER_BUILDX_PLATFORMS?=linux/amd64,linux/arm64 +DOCKER_BUILDX_BUILDER?=fgo-multi-platform + +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: @@ -20,8 +28,12 @@ clean: rm -rf ${BUILD_DIR} .PHONY: clean -image: - DOCKER_BUILDKIT=1 docker build -t ${DOCKER_IMAGE_NAME} --target ${COMPONENT} . +init-buildx: + docker buildx inspect fgo-multi-platform > /dev/null || docker buildx create --name=fgo-multi-platform +.PHONY: init-buildx + +image: init-buildx + docker buildx --builder=fgo-multi-platform build -t ${DOCKER_IMAGE_NAME} --target ${COMPONENT} --platform ${DOCKER_BUILDX_PLATFORMS} ${DOCKER_BUILDX_PUSH_FLAG} . .PHONY: image images: @@ -33,35 +45,10 @@ images: make image COMPONENT=jupyter-notebook .PHONY: images -push: - docker push ${DOCKER_IMAGE_NAME} -.PHONY: push - -push-all: - make push COMPONENT=device-plugin - make push COMPONENT=status-updater - make push COMPONENT=status-exporter - make push COMPONENT=topology-server - make push COMPONENT=mig-faker - make push COMPONENT=jupyter-notebook -.PHONY: push-all - restart: kubectl delete pod -l component=${COMPONENT} --force -n ${NAMESPACE} .PHONY: restart -deploy: image push -.PHONY: deploy - -deploy-all: - make image push COMPONENT=device-plugin - make image push COMPONENT=status-updater - make image push COMPONENT=status-exporter - make image push COMPONENT=topology-server - make image push COMPONENT=mig-faker - make image push COMPONENT=jupyter-notebook -.PHONY: deploy-all - image-test: mkdir -p /tmp/artifacts/test-results mkdir -p /tmp/artifacts/test-results/unit-tests