Skip to content

Commit

Permalink
Support multi-platform builds (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshaibi authored May 19, 2024
1 parent 21b1c50 commit b8d358a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 48 deletions.
12 changes: 3 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,13 @@ jobs:
- checkout
- pre_docker_commands
- run:
name: "Build Images"
name: "Build and Push Images"
environment:
CIRCLE_TAG: <<pipeline.git.revision>>
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=<<pipeline.git.revision>>
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:
Expand All @@ -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:
Expand Down
23 changes: 12 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
43 changes: 15 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit b8d358a

Please sign in to comment.