From fe0a414613e9033df12ff3bccb61204d8facc9e8 Mon Sep 17 00:00:00 2001 From: Djordje Lukic Date: Wed, 26 Apr 2023 13:48:50 +0200 Subject: [PATCH] Use the image service instead of the reference store for tagging The image store sends events when a new image is created/tagged, using it instead of the reference store makes sure we send the "tag" event when a new image is built using buildx. Signed-off-by: Djordje Lukic --- api/server/backend/build/backend.go | 2 +- builder/builder-next/builder.go | 2 ++ builder/builder-next/controller.go | 6 +++--- builder/builder-next/exporter/export.go | 16 ++++++++++------ cmd/dockerd/daemon.go | 1 + 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/api/server/backend/build/backend.go b/api/server/backend/build/backend.go index 0d81c0138a..03b6360bd4 100644 --- a/api/server/backend/build/backend.go +++ b/api/server/backend/build/backend.go @@ -92,7 +92,7 @@ func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string stdout := config.ProgressWriter.StdoutFormatter fmt.Fprintf(stdout, "Successfully built %s\n", stringid.TruncateID(imageID)) } - if imageID != "" { + if imageID != "" && !useBuildKit { err = tagger.TagImages(image.ID(imageID)) } return imageID, err diff --git a/builder/builder-next/builder.go b/builder/builder-next/builder.go index d770a2d7fd..000cc41e59 100644 --- a/builder/builder-next/builder.go +++ b/builder/builder-next/builder.go @@ -15,6 +15,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/backend" "github.com/docker/docker/builder" + containerimageexp "github.com/docker/docker/builder/builder-next/exporter" "github.com/docker/docker/daemon/config" "github.com/docker/docker/daemon/images" "github.com/docker/docker/libnetwork" @@ -70,6 +71,7 @@ type Opt struct { Root string Dist images.DistributionServices NetworkController libnetwork.NetworkController + ImageTagger containerimageexp.ImageTagger DefaultCgroupParent string RegistryHosts docker.RegistryHosts BuilderConfig config.BuilderConfig diff --git a/builder/builder-next/controller.go b/builder/builder-next/controller.go index 8f01d3228c..abb159b554 100644 --- a/builder/builder-next/controller.go +++ b/builder/builder-next/controller.go @@ -159,9 +159,9 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) { } exp, err := containerimageexp.New(containerimageexp.Opt{ - ImageStore: dist.ImageStore, - ReferenceStore: dist.ReferenceStore, - Differ: differ, + ImageStore: dist.ImageStore, + Differ: differ, + ImageTagger: opt.ImageTagger, }) if err != nil { return nil, err diff --git a/builder/builder-next/exporter/export.go b/builder/builder-next/exporter/export.go index e138a6f235..408231790c 100644 --- a/builder/builder-next/exporter/export.go +++ b/builder/builder-next/exporter/export.go @@ -7,10 +7,10 @@ import ( "strconv" "strings" + "github.com/docker/distribution/reference" distref "github.com/docker/distribution/reference" "github.com/docker/docker/image" "github.com/docker/docker/layer" - "github.com/docker/docker/reference" "github.com/moby/buildkit/exporter" "github.com/moby/buildkit/exporter/containerimage/exptypes" "github.com/moby/buildkit/util/compression" @@ -29,11 +29,15 @@ type Differ interface { EnsureLayer(ctx context.Context, key string) ([]layer.DiffID, error) } +type ImageTagger interface { + TagImageWithReference(imageID image.ID, newTag reference.Named) error +} + // Opt defines a struct for creating new exporter type Opt struct { - ImageStore image.Store - ReferenceStore reference.Store - Differ Differ + ImageStore image.Store + Differ Differ + ImageTagger ImageTagger } type imageExporter struct { @@ -206,10 +210,10 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp exporter.Source, } _ = configDone(nil) - if e.opt.ReferenceStore != nil { + if e.opt.ImageTagger != nil { for _, targetName := range e.targetNames { tagDone := oneOffProgress(ctx, "naming to "+targetName.String()) - if err := e.opt.ReferenceStore.AddTag(targetName, digest.Digest(id), true); err != nil { + if err := e.opt.ImageTagger.TagImageWithReference(image.ID(digest.Digest(id)), targetName); err != nil { return nil, tagDone(err) } _ = tagDone(nil) diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index c59e6f067b..bd1cdeecfa 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -295,6 +295,7 @@ func newRouterOptions(config *config.Config, d *daemon.Daemon) (routerOptions, e SessionManager: sm, Root: filepath.Join(config.Root, "buildkit"), Dist: d.DistributionServices(), + ImageTagger: d.ImageService(), NetworkController: d.NetworkController(), DefaultCgroupParent: cgroupParent, RegistryHosts: d.RegistryHosts(),