Skip to content

docker-to-squash.py: keep registry and namespace when re-fetching a multi-arch image - #9294

Open
linzch3 wants to merge 1 commit into
apache:masterfrom
linzch3:fix-9290-digest-repo
Open

linzch3 wants to merge 1 commit into
apache:masterfrom
linzch3:fix-9290-digest-repo

Conversation

@linzch3

@linzch3 linzch3 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fixes #9290.

When skopeo inspect --raw returns a manifest list, get_manifest_from_docker_image re-fetches the amd64 entry by digest, but built the new reference with image.split("/", 1)[-1].split(":", 1)[0]. That drops everything before the first /, so registry.example.com/team/app:1.0 became team/app@<digest> and myorg/app:1 became app@<digest> (i.e. library/app on Docker Hub).

Changes:

  • New helper get_image_without_tag_or_digest that drops only the tag and/or digest. A : is treated as a tag only if it comes after the last /, so a registry port like localhost:5000/app is kept.
  • get_manifest_from_docker_image uses it for the by-digest re-fetch.

How was the change tested

  • python -m unittest -v test_docker_to_squash in bin/ with Python 3.9: passes.
  • Added test_get_image_without_tag_or_digest (plain names, namespaces, registries with and without a port, digests) and a test that mocks skopeo inspect with a manifest list and checks the second call is docker://registry.example.com/team/app@sha256:.... With the fix reverted the second test fails with docker://team/app@sha256:amd.
  • Side note: the test stubs calculate_string_hash, because it gets str(out) (a str) and hashlib won't hash a str on Python 3. Didn't touch that here since it's a separate issue.

An AI assistant helped draft this change; I reviewed it and take responsibility for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker-to-squash.py: re-fetching a multi-arch image drops the registry or namespace

1 participant