Skip to content

Commit 1b85b28

Browse files
authored
🎨Director-v0: Pass headers on /manifests call to let the registry know we accept all manifest versions (#8241)
1 parent 5718eb4 commit 1b85b28

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

services/director/src/simcore_service_director/registry_proxy.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ async def _basic_auth_registry_request(
9494
raise ServiceNotAvailableError(service_name=path)
9595

9696
elif response.status_code >= status.HTTP_400_BAD_REQUEST:
97-
raise RegistryConnectionError(msg=str(response))
97+
raise RegistryConnectionError(
98+
msg=f"{response}: {response.text} for {request_url}"
99+
)
98100

99101
else:
100102
# registry that does not need an auth
@@ -165,7 +167,9 @@ async def _auth_registry_request( # noqa: C901
165167
if resp_wbasic.status_code == status.HTTP_404_NOT_FOUND:
166168
raise ServiceNotAvailableError(service_name=f"{url}")
167169
if resp_wbasic.status_code >= status.HTTP_400_BAD_REQUEST:
168-
raise RegistryConnectionError(msg=f"{resp_wbasic}")
170+
raise RegistryConnectionError(
171+
msg=f"{resp_wbasic}: {resp_wbasic.text} for {url}"
172+
)
169173
resp_data = await resp_wbasic.json(content_type=None)
170174
resp_headers = resp_wbasic.headers
171175
return (resp_data, resp_headers)
@@ -199,7 +203,22 @@ async def registry_request(
199203
if use_cache and (cached_response := await cache.get(cache_key)):
200204
assert isinstance(cached_response, tuple) # nosec
201205
return cast(tuple[dict, Mapping], cached_response)
202-
206+
# Add proper Accept headers for manifest requests for accepting both v1 and v2
207+
if "manifests/" in path and method.upper() == "GET":
208+
headers = session_kwargs.get("headers", {})
209+
headers.update(
210+
{
211+
"Accept": ", ".join(
212+
[
213+
"application/vnd.docker.distribution.manifest.v2+json",
214+
"application/vnd.docker.distribution.manifest.list.v2+json",
215+
"application/vnd.docker.distribution.manifest.v1+prettyjws",
216+
"application/json",
217+
]
218+
)
219+
}
220+
)
221+
session_kwargs["headers"] = headers
203222
app_settings = get_application_settings(app)
204223
try:
205224
response, response_headers = await _retried_request(
@@ -394,12 +413,29 @@ async def get_image_labels(
394413
media_type
395414
== "application/vnd.docker.distribution.manifest.list.v2+json"
396415
):
397-
raise DockerRegistryUnsupportedManifestSchemaVersionError(
398-
version=schema_version,
399-
service_name=image,
400-
service_tag=tag,
401-
reason="Multiple architectures images are currently not supported and need to be implemented",
416+
# default to x86_64 architecture
417+
_logger.info(
418+
"Image %s:%s is a docker image with multiple architectures. "
419+
"Currently defaulting to x86_64 architecture",
420+
image,
421+
tag,
402422
)
423+
manifests = request_result.get("manifests", [])
424+
if not manifests:
425+
raise DockerRegistryUnsupportedManifestSchemaVersionError(
426+
version=schema_version,
427+
service_name=image,
428+
service_tag=tag,
429+
reason="Manifest list is empty",
430+
)
431+
first_manifest_digest = manifests[0]["digest"]
432+
request_result, _ = await registry_request(
433+
app,
434+
path=f"{image}/manifests/{first_manifest_digest}",
435+
method="GET",
436+
use_cache=not update_cache,
437+
)
438+
403439
config_digest = request_result["config"]["digest"]
404440
# Fetch the config blob
405441
config_result, _ = await registry_request(

0 commit comments

Comments
 (0)