Skip to content

Conversation

vvoland
Copy link
Contributor

@vvoland vvoland commented Jun 27, 2024

- What I did
Fixed image tag event not being emitted when building images with buildkit and containerd integration.

- How I did it
See commits.

- How to verify it
TestBuildEmitsEvents

- Description for the changelog

containerd integration: `image tag` event is now properly emitted when building images with Buildkit

- A picture of a cute animal (not mandatory but encouraged)

@vvoland vvoland added area/builder Build kind/bugfix PR's that fix bugs area/builder/buildkit Build containerd-integration Issues and PRs related to containerd integration labels Jun 27, 2024
@vvoland vvoland added this to the 28.0.0 milestone Jun 27, 2024
@vvoland vvoland self-assigned this Jun 27, 2024
@vvoland vvoland requested a review from tonistiigi as a code owner June 27, 2024 16:42
@vvoland vvoland changed the title c8d/build: Log image tag event when image was built with Buildkit c8d/build: Log image tagged event when image was built with Buildkit Jun 27, 2024
@vvoland vvoland changed the title c8d/build: Log image tagged event when image was built with Buildkit c8d/build: Log image tag event when image was built with Buildkit Jun 27, 2024
for _, name := range strings.Split(out[string(exptypes.OptKeyName)], ",") {
ref, err := reference.ParseNormalizedNamed(name)
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 wondering if we're trying too hard here; my thinking is that ExporterInstance.Export would probably fail if any of the OptKeyName values was invalid. If it didn't fail then we _should _ assume that all of them were accepted.

From that perspective, we could just split the string, and call i.callbacks.Named(ctx, namedTagged, desc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's unexpected that the parsing will fail at this point (as highlighted in comment). The intent here was to provide a reference.Named type instead of raw string to match what the value actually represents.

Comment on lines 14 to 23
type ImageExportedByBuildkit = func(ctx context.Context, id string, desc ocispec.Descriptor)
type (
ImageExportedByBuildkit = func(ctx context.Context, id string, desc ocispec.Descriptor)
ImageNamedByBuildkit = func(ctx context.Context, ref reference.NamedTagged, desc ocispec.Descriptor)
)

type BuildkitCallbacks struct {
Exported ImageExportedByBuildkit
Named ImageNamedByBuildkit
}
Copy link
Member

Choose a reason for hiding this comment

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

What if we would change the signature of the callbacks to take event.Action as argument? In that case the callback could decide whether it needs to do anything.

We could either change the calllbacks to []Callback or (perhaps less code-churn) continue to accept a single callback (which could either have a switch event.Action, or be a wrapper for multiple callbacks)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like that because I consider the event.Action to be an implementation detail here.
These callbacks are meant to provide the integration point between the image service/daemon and the builder, that was naturally present with the legacy builder and is lost when using Buildkit.
This can potentially be useful for other things, not only emitting events, so IMO it doesn't make sense for the builder code to be concerned with daemon events at all.

daemon/build.go Outdated
Comment on lines 19 to 26
// ImageNamedByBuildkit is a callback that is called when an image is tagged by buildkit.
// Note: It is only called if the buildkit didn't call the image service itself to perform the tagging.
// Currently this only happens when the containerd image store is used.
func (daemon *Daemon) ImageNamedByBuildkit(ctx context.Context, ref reference.NamedTagged, desc ocispec.Descriptor) {
id := desc.Digest.String()
name := reference.FamiliarString(ref)
daemon.imageService.LogImageEvent(id, name, events.ActionTag)
}
Copy link
Member

Choose a reason for hiding this comment

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

See my previous comment; if we had event-type as argument; all of these could effectively be a single method that issues image events (I would change the ref argument to be a string and keep it generic (nameOrID, or could still be just ref as both are references as well).

vvoland added 3 commits July 2, 2024 12:34
This is only a callback that notifies about event so there is no way to
react to the error.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
When image is built with buildkit with containerd integration the image
service has no way of knowing that the image was tagged because buildkit
creates the image directly in containerd image store.

Add a callback that is called by the exporter wrapper.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
@vvoland vvoland force-pushed the c8d-buildkit-tag-event branch from 1db51bc to 53bc396 Compare July 2, 2024 10:35
@vvoland vvoland requested a review from thaJeztah July 3, 2024 09:10
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/builder/buildkit Build area/builder Build containerd-integration Issues and PRs related to containerd integration kind/bugfix PR's that fix bugs process/cherry-picked
Projects
3 participants