Skip to content

Commit

Permalink
apps: Use short ref if image hosted in docker hub
Browse files Browse the repository at this point in the history
Images hosted in the docker.io hub are referenced in a short form
without `docker.io` or `docker.io/library` prefixes. Therefore, the
algorithm should take it into account when looking for an image in the
local docker store (`repositiories.io`).

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Oct 2, 2024
1 parent 34ff365 commit 708c70a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions apps/get_layers_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,23 @@ def print_layer_details(layer: DockerStore.Layer):

image = docker_store.images_by_ref.get(img_uri)
if not image:
status("Image metadata are not found in local store; "
f"`SKIP_ARCHS` must be set for the image: {img_uri}", prefix="==== ")
continue
# Docker daemon stores image refs in repositories.json without the docker
# hub prefixes regardless whether an image is specified in a short or full format
# during docker pull or in docker-compose.yml. There are two possible short formats:
# 1. <name>:<tag> --> docker.io/library/<name>:<tag>
# 2. <org>/<name>:<tag> --> docker.io/<org>/<name>:<tag>
# Let's check if the image hosted in docker/.io and specified in a long format
# matches one of the images stored in the local docker store and references in
# the short form.
for docker_hub_prefix in ["docker.io/library/", "docker.io/"]:
if img_uri.startswith(docker_hub_prefix):
image = docker_store.images_by_ref.get(img_uri[len(docker_hub_prefix):])
if image:
break
if not image:
status("Image metadata are not found in local store; "
f"`SKIP_ARCHS` must be set for the image: {img_uri}", prefix="==== ")
continue

status(f"Image: {img_uri}", prefix="==== ")
for layer in image.layers:
Expand Down

0 comments on commit 708c70a

Please sign in to comment.