Skip to content

Commit

Permalink
feat: Support legacy docker image manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Sep 30, 2024
1 parent 493be6a commit e3a07b1
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/ai/backend/manager/container_registry/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class BaseContainerRegistry(metaclass=ABCMeta):
)
MEDIA_TYPE_DOCKER_MANIFEST: Final[str] = "application/vnd.docker.distribution.manifest.v2+json"

# Legacy manifest types (deprecated)
MEDIA_TYPE_DOCKER_MANIFEST_V1_PRETTY_JWS: Final[str] = (
"application/vnd.docker.distribution.manifest.v1+prettyjws"
)
MEDIA_TYPE_DOCKER_MANIFEST_V1_JSON: Final[str] = (
"application/vnd.docker.distribution.manifest.v1+json"
)

def __init__(
self,
db: ExtendedAsyncSAEngine,
Expand Down Expand Up @@ -279,7 +287,7 @@ async def _scan_tag(
return
content_type = resp.headers["Content-Type"]
resp.raise_for_status()
resp_json = await resp.json()
resp_json = json.loads(await resp.read())

async with aiotools.TaskGroup() as tg:
match content_type:
Expand All @@ -295,6 +303,14 @@ async def _scan_tag(
await self._process_oci_index(
tg, sess, rqst_args, image, tag, resp_json
)
case (
self.MEDIA_TYPE_DOCKER_MANIFEST_V1_PRETTY_JWS
| self.MEDIA_TYPE_DOCKER_MANIFEST_V1_JSON
):
await self._process_docker_v1_image(
tg, sess, rqst_args, image, tag, resp_json
)

case _:
log.warn("Unknown content type: {}", content_type)
raise RuntimeError(
Expand Down Expand Up @@ -438,6 +454,32 @@ async def _process_docker_v2_image(
}
await self._read_manifest(image, tag, manifests)

async def _process_docker_v1_image(
self,
tg: aiotools.TaskGroup,
sess: aiohttp.ClientSession,
rqst_args: Mapping[str, Any],
image: str,
tag: str,
image_info: Mapping[str, Any],
) -> None:
log.warning("Docker image manifest v1 is deprecated.")

architecture = image_info["architecture"]

manifest_list = [
{
"platform": {
"os": "linux",
"architecture": architecture,
},
"digest": tag,
}
]

rqst_args["headers"]["Accept"] = self.MEDIA_TYPE_DOCKER_MANIFEST
await self._read_manifest_list(sess, manifest_list, rqst_args, image, tag)

async def _read_manifest(
self,
image: str,
Expand Down

0 comments on commit e3a07b1

Please sign in to comment.