Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any plans for this library to support parsing image references with both tag and digest? #2704

Open
davidxia opened this issue Feb 3, 2025 · 3 comments

Comments

@davidxia
Copy link

davidxia commented Feb 3, 2025

I want to use some Golang library to parse container image names. Specifically, I want this library to parse an image reference string into its name, tag (if it exists), and digest (if it exists). I'd like the library to be able to handle an image reference with both tag and digest so I can do something like this.

imageWithTagAndDigest = "docker.io/library/ubuntu:v1@sha256:cc8ce713f3b4be3c72cca1f63ee78e3733bc7283472ecae367b47a128f7e4478"

ref, _ := Parse(imageWithTagAndDigest)

fmt.Println(ref.Name()) // docker.io/library/ubuntu
fmt.Println(ref.Tag()) // v1
fmt.Println(ref.Digest()) // sha256:cc8ce713f3b4be3c72cca1f63ee78e3733bc7283472ecae367b47a128f7e4478
imageWithTagOnly = "docker.io/library/ubuntu:v1"

ref, _ := Parse(imageWithTagOnly)

fmt.Println(ref.Name()) // docker.io/library/ubuntu
fmt.Println(ref.Tag()) // v1
fmt.Println(ref.Digest()) // "" or nil
imageWithDigestOnly = "docker.io/library/ubuntu@sha256:cc8ce713f3b4be3c72cca1f63ee78e3733bc7283472ecae367b47a128f7e4478"

ref, _ := Parse(imageWithDigestOnly)

fmt.Println(ref.Name()) // docker.io/library/ubuntu
fmt.Println(ref.Tag()) // "" or nil
fmt.Println(ref.Digest()) // sha256:cc8ce713f3b4be3c72cca1f63ee78e3733bc7283472ecae367b47a128f7e4478

Is there an official library that does this already? If not and this is the official library where this functionality would be added, is there any update on this issue or are contributions welcome for this change?

@davidxia
Copy link
Author

davidxia commented Feb 4, 2025

@mtrmac in your comment here, are you referring to this file https://github.com/containers/image/blob/main/docker/reference/reference.go? I think I'll need some more info or a usage example if you have time.

@mtrmac
Copy link
Collaborator

mtrmac commented Feb 4, 2025

There are plenty of uses in the codebase. The entry point is typically ParseNormalizedNamed.

@davidxia
Copy link
Author

davidxia commented Feb 4, 2025

I don't think that returns a struct with separate tag and digest fields? ParseNormalizedNamed only returns Named that only has a Name string and Reference string, right?

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

No branches or pull requests

2 participants