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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor reference parsing for oci-layout #3300

Merged
merged 1 commit into from
Nov 23, 2022

Conversation

jedevc
Copy link
Member

@jedevc jedevc commented Nov 22, 2022

馃崚 Cherry-picked off of #3118 (since it seems unlikely we'll take the functionality in the way that it's implemented for v0.11)

This PR introduces improvements to the user-facing error messages of the dockerfile oci-layout functionality. Essentially, we achieve this by using all of containerd's/distribution's reference parsers instead of doing manual string manipulation.

The main internal-api change that this introduces is combining the reference with the digest together in the OCILayout llb - we can just pass the whole thing together, instead of needing to later reconstruct it back together.

Signed-off-by: Justin Chadwell me@jedevc.com

@jedevc jedevc added this to the v0.11.0 milestone Nov 22, 2022
@jedevc jedevc force-pushed the oci-layout-reference-parsing branch from d8f24d5 to 4757e53 Compare November 22, 2022 15:30
storeID := parsed.Hostname()

rslvr = getOCILayoutResolver(storeID, sm, "", g)
rslvr = getOCILayoutResolver(parsed.Hostname(), sm, "", g)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised of the use of Hostname() in here. Even if you consider this input same as the image reference it doesn't mean that Hostname() is the storeID. storeID is the name that isn't digest or tag in that case. The reason this works is because it uses the containerd reference pkg that only deals with full reference strings(not normalized/familiar). For that library alpine:latest is invalid and doesn't work. It needs to be converted to docker.io/library/alpine before what doesn't make sense for the OCI case.

So the current code relies on accidental side-effect on passing invalid parameters.

Copy link
Member Author

@jedevc jedevc Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is weird.

I've tried reworking this around, but the core of the issue comes in that because we prefix the dummy image name in the dockerfile frontend, we can't just take parsed.Locator which would feel more logical IMO.

Some ideas:

  • We could change ResolveImageConfig to take <store-id>@<digest> with no need for the dummy image name - but then the argument isn't an actual ref, which definitely feels confusing.
  • We could modify the Opts passed to ResolveImageConfig to take a store id, so that then we have access to that, similar to the rest of the cases in this file where we call getOCILayoutResolver where we just ignore the ref entirely and get the store id from another specified location.

I think there's also a level of confusion about the dummy name eventually going to be replaced with a name that we could do tag resolution with, but I think as we've discussed previously, we'd prefer to do all that resolution client-side (similar to how we do local cache, etc), instead of somehow forwarding the data of the image layout into buildkit.

Also, related to dummy names - we should try and select some better dummy names, since these will show up in the progress, so we should make an effort to make them as user-readable as well can.

frontend/dockerfile/builder/build.go Outdated Show resolved Hide resolved
frontend/dockerfile/builder/build.go Outdated Show resolved Hide resolved
frontend/dockerfile/builder/build.go Outdated Show resolved Hide resolved
client/llb/source.go Outdated Show resolved Hide resolved
Instead of using custom parsing mechansisms for references in
oci-layout, we use containerd's reference.Parse or docker distribution's
reference.Parse (depending on where we do the parsing, and what's
consistent with the file where it's already done). These operations are
neater than manually parsing, and have hopefully more consistent error
messages, and better handling of labels (for if/when those are
introduced).

Signed-off-by: Justin Chadwell <me@jedevc.com>
@jedevc jedevc force-pushed the oci-layout-reference-parsing branch from 4757e53 to 6340184 Compare November 23, 2022 14:06
@tonistiigi tonistiigi merged commit 0c38289 into moby:master Nov 23, 2022
@jedevc jedevc mentioned this pull request Dec 7, 2022
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.

None yet

2 participants