Skip to content

Commit

Permalink
fix: image checks for some oci images fail (#1995)
Browse files Browse the repository at this point in the history
This occurs because some images (most likely when they support multiple
architectures) have an index instead of just a manifest. An OCI index
refers to a set of images. But when we were checking for images we were
only checking for the manifest and did not have the option to support an
index content type.
  • Loading branch information
olevski authored Oct 16, 2024
1 parent f5a3381 commit b7cd7b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions renku_notebooks/api/classes/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import Any, Optional
from typing import Any, Optional, cast

import requests
from werkzeug.datastructures import WWWAuthenticate
Expand All @@ -13,7 +13,8 @@

class ManifestTypes(Enum):
docker_v2: str = "application/vnd.docker.distribution.manifest.v2+json"
oci_v1: str = "application/vnd.oci.image.manifest.v1+json"
oci_v1_manifest: str = "application/vnd.oci.image.manifest.v1+json"
oci_v1_index: str = "application/vnd.oci.image.index.v1+json"


@dataclass
Expand Down Expand Up @@ -62,8 +63,19 @@ def get_image_manifest(self, image: "Image") -> Optional[dict[str, Any]]:
headers["Authorization"] = f"Bearer {token}"
res = requests.get(image_digest_url, headers=headers)
if res.status_code != 200:
headers["Accept"] = ManifestTypes.oci_v1.value
headers["Accept"] = ManifestTypes.oci_v1_manifest.value
res = requests.get(image_digest_url, headers=headers)
if res.status_code != 200:
headers["Accept"] = ManifestTypes.oci_v1_index.value
res = requests.get(image_digest_url, headers=headers)
if res.status_code == 200:
index_parsed = res.json()
manifest = next(
(man for man in index_parsed.get("manifests", []) if man.get("platform", {}).get("os") == "linux"),
None,
)
manifest = cast(dict[str, Any] | None, manifest)
return manifest
if res.status_code != 200:
return None
return res.json()
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_public_image_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def test_public_image_name_parsing(name, expected):
("renku/singleuser", True),
("madeuprepo/madeupproject:tag", False),
("olevski90/oci-image:0.0.1", True),
("ghcr.io/linuxserver/nginx:latest", True)
],
)
@pytest.mark.integration
Expand Down

0 comments on commit b7cd7b3

Please sign in to comment.