Skip to content

Commit

Permalink
core: cli modelcard option, E2E test refactor
Browse files Browse the repository at this point in the history
Signed-off-by: tarilabs <[email protected]>
  • Loading branch information
tarilabs committed Feb 18, 2025
1 parent 36e7801 commit 8b8ad1c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ jobs:
e2e/repeat.sh kubectl apply --server-side -f https://github.com/kserve/kserve/releases/download/v0.14.0/kserve-cluster-resources.yaml
kubectl patch configmap/inferenceservice-config -n kserve --type=strategic -p '{"data": {"deploy": "{\"defaultDeploymentMode\": \"RawDeployment\"}"}}'
e2e/enable-modelcar.sh
- name: Load image in KinD for amd64
run: |
- name: Run OLOT tutorial of README, and load image in KinD for amd64
run: |
IMAGE_DIR=download
OCI_REGISTRY_SOURCE=quay.io/mmortari/hello-world-wait:latest
OCI_REGISTRY_DESTINATION=localhost:5001/nstestorg/modelcar
rm -rf $IMAGE_DIR
skopeo copy --multi-arch all docker://${OCI_REGISTRY_SOURCE} oci:${IMAGE_DIR}:latest
poetry run olot $IMAGE_DIR tests/data/sample-model/model.joblib --modelcard tests/data/sample-model/README.md
# copy modelcar from oci-layout to the local docker registry
skopeo copy --tls-verify=false --multi-arch all oci:${IMAGE_DIR}:latest docker://${OCI_REGISTRY_DESTINATION}
# make sure the annotation is present
digest=$(skopeo inspect --tls-verify=false --raw docker://localhost:5001/nstestorg/modelcar | jq -r '.manifests[] | select(.platform.architecture == "amd64") | .digest')
skopeo inspect docker://${OCI_REGISTRY_DESTINATION}@$digest --raw | jq -e '.layers | last | has("annotations")'
# tag amd64 as modelcar:v1 and load image in KinD cluster
skopeo copy --src-tls-verify=false docker://localhost:5001/nstestorg/modelcar@$digest docker-daemon:localhost:5001/nstestorg/modelcar:v1
kind load docker-image -n "kind" "localhost:5001/nstestorg/modelcar:v1"
- name: Apply Isvc using Modelcar # since the enable modelcar restart controller pod, better guard the kubectl apply
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ skopeo copy --multi-arch all docker://${OCI_REGISTRY_SOURCE} oci:${IMAGE_DIR}:la
# oras copy --to-oci-layout $OCI_REGISTRY_SOURCE ./${IMAGE_DIR}:latest
# chmod +w ${IMAGE_DIR}/blobs/sha256/*

# Appends to the image found in `download` the files `model.joblib` and `README.md`
poetry run olot $IMAGE_DIR tests/data/sample-model/model.joblib tests/data/sample-model/README.md
# Appends to the image found in `download` the files `model.joblib` and as ModelCarD the `README.md`
poetry run olot $IMAGE_DIR tests/data/sample-model/model.joblib --modelcard tests/data/sample-model/README.md

# Pushes the (updated) image found in `download` folder to the registry `quay.io/mmortari/demo20241208` with tag `latest`
skopeo copy --multi-arch all oci:${IMAGE_DIR}:latest docker://${OCI_REGISTRY_DESTINATION}
Expand Down Expand Up @@ -64,6 +64,10 @@ Cleanup your local image
podman image rm quay.io/mmortari/demo20241208:latest
```

### Dev notes

If copying the resulting image to local filesystem oci-layout using skopeo, make sure to enable `--dest-oci-accept-uncompressed-layers` option.

### As a Python Package

Install the package
Expand Down
4 changes: 3 additions & 1 deletion olot/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def oci_layers_on_top(ocilayout: Path, model_files: List[os.PathLike], modelcard
config_sha = mc_json_hash
manifest.config.digest = "sha256:" + config_sha
manifest.config.size = os.stat(ocilayout / "blobs" / "sha256" / config_sha).st_size
manifest.annotations["io.opendatahub.temp.author"] = "olot" # type:ignore
if manifest.annotations is None:
manifest.annotations = {}
manifest.annotations["io.opendatahub.temp.author"] = "olot"
manifest_json = manifest.model_dump_json(exclude_none=True)
with open(ocilayout / "blobs" / "sha256" / manifest_hash, "w") as cf:
cf.write(manifest_json)
Expand Down
6 changes: 4 additions & 2 deletions olot/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from os import PathLike
from pathlib import Path
import click

Expand All @@ -7,7 +8,8 @@


@click.command()
@click.option("-m", "--modelcard", type=click.Path(exists=True, file_okay=True, dir_okay=False))
@click.argument('ocilayout', type=click.Path(exists=True, file_okay=False, dir_okay=True))
@click.argument('model_files', nargs=-1)
def cli(ocilayout: str, model_files):
oci_layers_on_top(Path(ocilayout), model_files)
def cli(ocilayout: str, modelcard: PathLike, model_files):
oci_layers_on_top(Path(ocilayout), model_files, modelcard)

0 comments on commit 8b8ad1c

Please sign in to comment.