Repository navigation
Keep registry and namespace when re-fetching a manifest list in bin/docker-to-squash.py - #9299
Closed
ToniAdreal wants to merge 1 commit into
Closed
ToniAdreal wants to merge 1 commit into
ToniAdreal wants to merge 1 commit into
Conversation
…r-to-squash.py
When skopeo returns a manifest list, get_manifest_from_docker_image re-fetches the amd64 manifest by digest, but it builds the new reference from image.split('/', 1)[-1].split(':', 1)[0], which drops the registry and the namespace: registry.example.com/team/app:1.0 is re-fetched as team/app@<digest>, and myorg/app:1 as app@<digest> (Docker Hub library/app). Strip only the tag instead: drop any digest part first, then remove a tag only when the last path component contains a colon, so a registry port is never mistaken for a tag.
Signed-off-by: ToniAdreal <184365500+ToniAdreal@users.noreply.github.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9290.
When
skopeo inspect --rawreturns a manifest list,get_manifest_from_docker_imageinbin/docker-to-squash.pyre-fetches the amd64 manifest by digest, but it builds the new reference withwhich drops the registry and the namespace. Reproduced on Python 3.12.3 with
skopeostubbed (first answer a manifest list with amd64 digestsha256:bbb222):registry.example.com/team/app:1.0-> second fetch isdocker://team/app@sha256:bbb222(registry gone)registry.example.com:5000/team/app:1.0->docker://team/app@sha256:bbb222(registry and port gone)myorg/app:1->docker://app@sha256:bbb222(namespace gone, resolves to Docker Hublibrary/app)The fix strips only the tag: any digest part is dropped first, then a tag is removed only when the last path component contains a colon, so a registry port is never mistaken for a tag. After the fix the second fetches are
docker://registry.example.com/team/app@sha256:bbb222,docker://registry.example.com:5000/team/app@sha256:bbb222, anddocker://myorg/app@sha256:bbb222.Testing: the stubbed repro above was run before and after the change (with
calculate_string_hashstubbed in the harness to isolate the reference logic, since its Python 3 failure is #9291). The existing suite also passes against this change (python3 -m unittest test_docker_to_squash.py, with the one-linecollections.abcimport shim from the #9291 PR in a scratch copy, since the suite cannot be imported on Python 3.10+ until that lands).This is one of the four docker-to-squash.py fixes #9284 left to separate PRs.