-
Notifications
You must be signed in to change notification settings - Fork 584
Match names from both containerd and containerization annotations #223
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
Conversation
9d19be5 to
70b8fcf
Compare
| let newDockerfile: String = | ||
| """ | ||
| FROM local-only:\(imageName) | ||
| FROM \(imageName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a typo in the test, because imageName has local-only prefix already:
https://github.com/apple/container/blob/main/Tests/CLITests/Subcommands/Build/CLIBuilderTest.swift#L63
| } | ||
|
|
||
| return annotations[AnnotationKeys.containerizationImageName] == name | ||
| || annotations[AnnotationKeys.containerdImageName] == name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little tricky - yeah adding this check would fix the issue we are seeing, but we dont feel its right that an image we build without a domain in its tag, automatically gets assigned one.
I think we should change the behavior so that the reference we get from the build container does not have the domain prepended if its a locally built image
And I think that happens here :
https://github.com/apple/container-builder-shim/blob/main/pkg/build/frontend.go#L144
Tagging @katiewasnothere for some more input
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean saying that an image automatically gets domain assigned? It's a fully qualified reference and all normalized names are with domain, so ParseAnyReference returns it in this format.
I don't have a strong opinion here, so it you decide to get rid of the domain here, I can make corresponding changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example if the Dockerfile being built is
FROM local-image:test
...
The expectation is that somewhere in the build process, the container-image-service will be asked about the existence of local-image:test by the builder.
But because the builder is parsing that base image reference using reference. ParseAnyReference (which has the assumption that an image should get the default domain of docker.io) - the container-image-service ends up getting a request for docker.io/local-image:test
And this diff makes it such that we intercept the request b/w the build container and image service to work around that assumption
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add to the above - we still want the nice UX of something like this still working
FROM alpine:latest
...
And to support that container does some normalization of its own - at a high level it does
- Check if "alpine:latest" exists as an image in the daemon
- If not normalize it using the configured default registry (see
container registry default set) - Check if an image with normalized reference exists in the daemon (will be of the form
<domain>/alpine:latest) - If that fails - pull the image from the registry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I got the idea. And I agree that the decision about the default registry should be made on the container-image-service side, not on container-build-shim.
I made some changes in the PR, that should both support the flow you described and fix the initial bug. Next I'm going to make a PR to the shim repo to change the reference parsing and get rid of the default docker domain in the request. Does it sound like a good plan for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay after lengthy investigation, I think there's not really a way here for us to avoid buildkit adding the docker.io/library prefix to an image reference other than us modifying the dockerfile that we send to builder, which seems like a bad plan. Given that, I think our only option is to match the reference to either the container.name or containerization.name as you've done here. I don't think we need the builder side changes though.
@adityaramani is out for a few days, but I'd like to wait for his input here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we call Dockerfile2LLB after we resolve images: https://github.com/apple/container-builder-shim/blob/35406d303bc165a090df812d75971d90d4e24f9f/pkg/build/frontend.go#L75-L80
But I agree that it becomes too complex and fragile. We can skip container-builder-shim changes then and keep this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think its possible to make a variation of this change in BuildImageResolver.swift when we try to fetch the image?
Something like this?
let img = try await {
if ref.startsWith("docker.io/library") {
trimmedRef = ref["docker.io/library".count + 1 : ]
if i = ClientImage.get(trimmedRef) {
return i
}
guard let img = try? await ClientImage.pull(reference: ref, platform: platform) else {
return try await ClientImage.fetch(reference: ref, platform: platform)
}
return img
}
}()
The idea behind this is to restrict this change only to affect the build flow. Do ya'll think this would work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather we use the containerization.name as the source of truth. It's possible that someone has the images alpine (local) and docker.io/library/alpine (pulled). If we always stripped out docker.io/library for the image on a build, we'd always return the local alpine image.
Signed-off-by: Alexey <[email protected]>
70b8fcf to
232bf12
Compare
…e normalized reference in the response Signed-off-by: Alexey <[email protected]>
|
Hi @makhov 👋🏾 , Thanks a lot for putting the effort into this and suggesting improvements here. I really appreciate your contribution! However, this issue is best addressed by fixing the resolver logic itself, rather than at this layer of the stack. Specifically, the resolver shouldn't automatically prefix a default registry if none was provided. Here's the PR addressing this: apple/container-builder-shim#34 I’m happy to discuss this further if you have questions |
|
@wlan0 No problem! I left a comment in the mentioned PR, we can discuss further details there, so feel free to close this one |
|
Closing in favor of apple/container-builder-shim#34. Thanks again @makhov! |
Fixes #211
Currently, it matches only with
.containerizationImageNameannotation, but it contains name withoutdocker.io/libraryprefix..containerdImageNameannotation has the prefix.