From 8d73093cb9a1c4baab0ab854a7b9b9bafc9bd974 Mon Sep 17 00:00:00 2001 From: Angel Misevski Date: Fri, 1 Mar 2024 16:31:27 -0500 Subject: [PATCH] Add Dockerfile for installing kit as a KServe ClusterStorageContainer Add a Dockerfile that builds an image suitable to using `kit` as a ClusterStorageContainer for KServe installs. Included is a short README.md that gives a general overview of how to use this container. To come: automating multi-platform builds of this image to allow it to be more easily used. --- build/dockerfiles/KServe/README.md | 56 ++++++++++++++++++++++ build/dockerfiles/KServe/entrypoint.sh | 23 +++++++++ build/dockerfiles/KServe/kserve.Dockerfile | 34 +++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 build/dockerfiles/KServe/README.md create mode 100755 build/dockerfiles/KServe/entrypoint.sh create mode 100644 build/dockerfiles/KServe/kserve.Dockerfile diff --git a/build/dockerfiles/KServe/README.md b/build/dockerfiles/KServe/README.md new file mode 100644 index 00000000..839a43ba --- /dev/null +++ b/build/dockerfiles/KServe/README.md @@ -0,0 +1,56 @@ +# Kitops ClusterStorageContainer image for KServe + +The Dockerfile in this directory is used to build an image that can run as a ClusterStorageContainer for [KServe](https://kserve.github.io/website/master/). + +## Building +To build the image, `docker` is required. From the root of this repository, set the `$KIT_KSERVE_IMAGE` to the image tag you want to build and run +```bash +docker build . \ + -f build/dockerfiles/KServe/kserve.Dockerfile \ + -t $KIT_KSERVE_IMAGE \ + --build-arg version="next" \ + --build-arg gitCommit=$(git rev-parse HEAD) +``` + +## Installing +The following process will create a new ClusterStorageContainer that uses `kit` to support KServe InferenceServices with storage URIs that have the `kit://` prefix. + +Create the following ClusterStorageContainer custom resource in a Kubernetes cluster with KServe installed +```yaml +apiVersion: "serving.kserve.io/v1alpha1" +kind: ClusterStorageContainer +metadata: + name: kitops +spec: + container: + name: kit-storage-initializer + image: $KIT_KSERVE_IMAGE + imagePullPolicy: Always + env: + - name: KIT_UNPACK_FLAGS + value: "" # Add extra flags for the `kit unpack` command + resources: + requests: + memory: 100Mi + cpu: 100m + limits: + memory: 1Gi + supportedUriFormats: + - prefix: kit:// +``` + +Once this CR is installed, modelkits can be used in InferenceServices by specifying with the `kit://` URI: +```yaml +storageUri: kit:// +``` + +## Configuration +The Kit KServe container supports specifying additional flags as supported by the `kit unpack` command. Additional flags are read from the `KIT_UNPACK_FLAGS` environment variable in the ClusterStorageContainer. For example, the following adds `-v` and `--plain-http` for all unpack commands: +```yaml + env: + - name: KIT_UNPACK_FLAGS + value: "-v --plain-http" +``` + +## Additional links +* [KServe ClusterStorageContainer documentation](https://kserve.github.io/website/master/modelserving/storage/storagecontainers/) diff --git a/build/dockerfiles/KServe/entrypoint.sh b/build/dockerfiles/KServe/entrypoint.sh new file mode 100755 index 00000000..6ececf23 --- /dev/null +++ b/build/dockerfiles/KServe/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +echo "Binary version info:" +kit version + +read -r -a UNPACK_FLAGS <<< "$KIT_UNPACK_FLAGS" + +if [ $# != 2 ]; then + echo "Usage: entrypoint.sh " + exit 1 +fi + +REPO_NAME="${1#kit://}" +OUTPUT_DIR="$2" + +echo "Unpacking $REPO_NAME to $OUTPUT_DIR" +echo "Unpack options: ${KIT_UNPACK_FLAGS}" +kit unpack "$REPO_NAME" -d "$OUTPUT_DIR" "${UNPACK_FLAGS[@]}" + +echo "Unpacked modelkit:" +cat "$OUTPUT_DIR/Kitfile" diff --git a/build/dockerfiles/KServe/kserve.Dockerfile b/build/dockerfiles/KServe/kserve.Dockerfile new file mode 100644 index 00000000..a5f08cbd --- /dev/null +++ b/build/dockerfiles/KServe/kserve.Dockerfile @@ -0,0 +1,34 @@ +FROM docker.io/library/golang:alpine AS builder + +RUN apk --no-cache upgrade && apk add --no-cache git +ARG version=next +ARG gitCommit= + +WORKDIR /build + +# Cache dependencies in separate layer +COPY ["go.mod", "go.sum", "./"] +RUN go mod download + +COPY . . +RUN \ + CGO_ENABLED=0 go build \ + -o kit \ + -ldflags="-s -w -X kitops/pkg/cmd/version.Version=${version} -X kitops/pkg/cmd/version.GitCommit=$gitCommit -X kitops/pkg/cmd/version.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" + +FROM docker.io/library/alpine +ENV USER_ID=1001 \ + USER_NAME=kit \ + HOME=/home/user/ + +RUN apk --no-cache upgrade && \ + apk add --no-cache bash && \ + mkdir -p /home/user/ && \ + adduser -D $USER_NAME -h $HOME -u $USER_ID + +USER ${USER_ID} + +COPY --from=builder /build/kit /usr/local/bin/kit +COPY build/dockerfiles/KServe/entrypoint.sh /usr/local/bin/entrypoint.sh + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]