Skip to content

Commit

Permalink
Add Dockerfile for installing kit as a KServe ClusterStorageContainer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amisevsk committed Mar 15, 2024
1 parent 88b13b3 commit 8d73093
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
56 changes: 56 additions & 0 deletions build/dockerfiles/KServe/README.md
Original file line number Diff line number Diff line change
@@ -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://<modelkit-reference>
```

## 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/)
23 changes: 23 additions & 0 deletions build/dockerfiles/KServe/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 <src-uri> <dest-path>"
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"
34 changes: 34 additions & 0 deletions build/dockerfiles/KServe/kserve.Dockerfile
Original file line number Diff line number Diff line change
@@ -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=<unknown>

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"]

0 comments on commit 8d73093

Please sign in to comment.