From 574f4b48c40275aed80c30a99cf4327c89fd97d5 Mon Sep 17 00:00:00 2001 From: Matt Prahl Date: Wed, 19 Feb 2025 04:38:27 -0500 Subject: [PATCH] Various fixes for issues encountered using the read me example (#16) * Fix the import in the example in the read me Signed-off-by: mprahl * Pass --remove-signatures to skopeo copy This adds support for copying from registries that leverage signatures (e.g. registry.access.redhat.com). Signed-off-by: mprahl * Add support for a string path for oci_layers_on_top Without this code, Python would accept a string but verify_ocilayout would fail when joining paths. Signed-off-by: mprahl * Allow pushing container images with credentials Signed-off-by: mprahl * code review remove redundant Signed-off-by: tarilabs --------- Signed-off-by: mprahl Signed-off-by: tarilabs Co-authored-by: tarilabs --- README.md | 2 +- olot/backend/skopeo.py | 4 ++-- olot/basics.py | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ebf1c97..e0afa51 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ pip install olot Import and add layers onto a locally available model (using skopeo): ```python -from olot.oci_artifact import oci_layers_on_top +from olot.basic import oci_layers_on_top from olot.backend.skopeo import skopeo_pull, skopeo_push model_dir = 'download' diff --git a/olot/backend/skopeo.py b/olot/backend/skopeo.py index a398b9c..88f5f65 100644 --- a/olot/backend/skopeo.py +++ b/olot/backend/skopeo.py @@ -10,10 +10,10 @@ def is_skopeo() -> bool : def skopeo_pull(base_image: str, dest: typing.Union[str, os.PathLike]): if isinstance(dest, os.PathLike): dest = str(dest) - return subprocess.run(["skopeo", "copy", "--multi-arch", "all", "docker://"+base_image, "oci:"+dest+":latest"], check=True) + return subprocess.run(["skopeo", "copy", "--multi-arch", "all", "--remove-signatures", "docker://"+base_image, "oci:"+dest+":latest"], check=True) def skopeo_push(src: typing.Union[str, os.PathLike], oci_ref: str): if isinstance(src, os.PathLike): src = str(src) - return subprocess.run(["skopeo", "copy", "--multi-arch", "all", "--dest-tls-verify=false", "--dest-no-creds", "oci:"+src+":latest", "docker://"+oci_ref], check=True) + return subprocess.run(["skopeo", "copy", "--multi-arch", "all", "--dest-tls-verify=false", "oci:"+src+":latest", "docker://"+oci_ref], check=True) diff --git a/olot/basics.py b/olot/basics.py index 6d8f226..a6174ee 100644 --- a/olot/basics.py +++ b/olot/basics.py @@ -17,7 +17,10 @@ from olot.utils.files import tarball_from_file, targz_from_file from olot.utils.types import compute_hash_of_str -def oci_layers_on_top(ocilayout: Path, model_files: List[os.PathLike], modelcard: typing.Union[os.PathLike, None] = None): +def oci_layers_on_top(ocilayout: typing.Union[str, os.PathLike], model_files: List[os.PathLike], modelcard: typing.Union[os.PathLike, None] = None): + if not isinstance(ocilayout, Path): + ocilayout = Path(ocilayout) + verify_ocilayout(ocilayout) ocilayout_root_index = read_ocilayout_root_index(ocilayout) ocilayout_indexes: Dict[str, OCIImageIndex] = crawl_ocilayout_indexes(ocilayout, ocilayout_root_index)