From 6b6fa9d5fa611c85aa2c8a885c33f9a40fafb64a Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 11 Jun 2024 12:23:17 +0200 Subject: [PATCH] history: fix empty Exporters attribute Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- client/client_test.go | 2 ++ control/control.go | 1 + exporter/containerimage/export.go | 13 ++++++++++++- exporter/exporter.go | 2 ++ exporter/local/export.go | 13 ++++++++++++- exporter/oci/export.go | 17 ++++++++++++++--- exporter/tar/export.go | 13 ++++++++++++- .../dockerfile/dockerfile_provenance_test.go | 1 + solver/llbsolver/solver.go | 12 +++++------- 9 files changed, 61 insertions(+), 13 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index fce54e58b1a3..14389decb820 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -2940,6 +2940,7 @@ func testMultipleExporters(t *testing.T, sb integration.Sandbox) { if workers.IsTestDockerd() { require.Len(t, ev.Record.Result.Results, 1) + require.Len(t, ev.Record.Exporters, 5) if workers.IsTestDockerdMoby(sb) { require.Equal(t, images.MediaTypeDockerSchema2Config, ev.Record.Result.Results[0].MediaType) } else { @@ -2947,6 +2948,7 @@ func testMultipleExporters(t *testing.T, sb integration.Sandbox) { } } else { require.Len(t, ev.Record.Result.Results, 2) + require.Len(t, ev.Record.Exporters, 6) require.Equal(t, images.MediaTypeDockerSchema2Manifest, ev.Record.Result.Results[0].MediaType) require.Equal(t, ocispecs.MediaTypeImageManifest, ev.Record.Result.Results[1].MediaType) } diff --git a/control/control.go b/control/control.go index 40058f8fe1f1..f90367efdfb4 100644 --- a/control/control.go +++ b/control/control.go @@ -372,6 +372,7 @@ func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (* if err != nil { return nil, err } + bklog.G(ctx).Debugf("resolve exporter %s with %v", ex.Type, ex.Attrs) expi, err := exp.Resolve(ctx, i, ex.Attrs) if err != nil { return nil, err diff --git a/exporter/containerimage/export.go b/exporter/containerimage/export.go index ef4172e21b07..63cab282a3fe 100644 --- a/exporter/containerimage/export.go +++ b/exporter/containerimage/export.go @@ -20,6 +20,7 @@ import ( cerrdefs "github.com/containerd/errdefs" "github.com/moby/buildkit/cache" cacheconfig "github.com/moby/buildkit/cache/config" + "github.com/moby/buildkit/client" "github.com/moby/buildkit/exporter" "github.com/moby/buildkit/exporter/containerimage/exptypes" "github.com/moby/buildkit/session" @@ -68,6 +69,7 @@ func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]stri i := &imageExporterInstance{ imageExporter: e, id: id, + attrs: opt, opts: ImageCommitOpts{ RefCfg: cacheconfig.RefConfig{ Compression: compression.New(compression.Default), @@ -168,7 +170,8 @@ func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]stri type imageExporterInstance struct { *imageExporter - id int + id int + attrs map[string]string opts ImageCommitOpts push bool @@ -194,6 +197,14 @@ func (e *imageExporterInstance) Config() *exporter.Config { return exporter.NewConfigWithCompression(e.opts.RefCfg.Compression) } +func (e *imageExporterInstance) Type() string { + return client.ExporterImage +} + +func (e *imageExporterInstance) Attrs() map[string]string { + return e.attrs +} + func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source, inlineCache exptypes.InlineCache, sessionID string) (_ map[string]string, descref exporter.DescriptorReference, err error) { src = src.Clone() if src.Metadata == nil { diff --git a/exporter/exporter.go b/exporter/exporter.go index bbaf4b8a49a0..c16f174558ba 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -22,6 +22,8 @@ type ExporterInstance interface { ID() int Name() string Config() *Config + Type() string + Attrs() map[string]string Export(ctx context.Context, src *Source, inlineCache exptypes.InlineCache, sessionID string) (map[string]string, DescriptorReference, error) } diff --git a/exporter/local/export.go b/exporter/local/export.go index b0426a4d412d..be4e064cb443 100644 --- a/exporter/local/export.go +++ b/exporter/local/export.go @@ -8,6 +8,7 @@ import ( "time" "github.com/moby/buildkit/cache" + "github.com/moby/buildkit/client" "github.com/moby/buildkit/exporter" "github.com/moby/buildkit/exporter/containerimage/exptypes" "github.com/moby/buildkit/exporter/util/epoch" @@ -38,6 +39,7 @@ func New(opt Opt) (exporter.Exporter, error) { func (e *localExporter) Resolve(ctx context.Context, id int, opt map[string]string) (exporter.ExporterInstance, error) { i := &localExporterInstance{ id: id, + attrs: opt, localExporter: e, } _, err := i.opts.Load(opt) @@ -50,7 +52,8 @@ func (e *localExporter) Resolve(ctx context.Context, id int, opt map[string]stri type localExporterInstance struct { *localExporter - id int + id int + attrs map[string]string opts CreateFSOpts } @@ -63,6 +66,14 @@ func (e *localExporterInstance) Name() string { return "exporting to client directory" } +func (e *localExporterInstance) Type() string { + return client.ExporterLocal +} + +func (e *localExporterInstance) Attrs() map[string]string { + return e.attrs +} + func (e *localExporter) Config() *exporter.Config { return exporter.NewConfig() } diff --git a/exporter/oci/export.go b/exporter/oci/export.go index 3748f536caa4..5e41b3737876 100644 --- a/exporter/oci/export.go +++ b/exporter/oci/export.go @@ -14,6 +14,7 @@ import ( "github.com/distribution/reference" "github.com/moby/buildkit/cache" cacheconfig "github.com/moby/buildkit/cache/config" + "github.com/moby/buildkit/client" "github.com/moby/buildkit/exporter" "github.com/moby/buildkit/exporter/containerimage" "github.com/moby/buildkit/exporter/containerimage/exptypes" @@ -34,8 +35,8 @@ import ( type ExporterVariant string const ( - VariantOCI = "oci" - VariantDocker = "docker" + VariantOCI = client.ExporterOCI + VariantDocker = client.ExporterDocker ) const ( @@ -62,6 +63,7 @@ func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]stri i := &imageExporterInstance{ imageExporter: e, id: id, + attrs: opt, tar: true, opts: containerimage.ImageCommitOpts{ RefCfg: cacheconfig.RefConfig{ @@ -100,7 +102,8 @@ func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]stri type imageExporterInstance struct { *imageExporter - id int + id int + attrs map[string]string opts containerimage.ImageCommitOpts tar bool @@ -115,6 +118,14 @@ func (e *imageExporterInstance) Name() string { return fmt.Sprintf("exporting to %s image format", e.opt.Variant) } +func (e *imageExporterInstance) Type() string { + return string(e.opt.Variant) +} + +func (e *imageExporterInstance) Attrs() map[string]string { + return e.attrs +} + func (e *imageExporterInstance) Config() *exporter.Config { return exporter.NewConfigWithCompression(e.opts.RefCfg.Compression) } diff --git a/exporter/tar/export.go b/exporter/tar/export.go index 36b5d1cf0154..76892d318c4f 100644 --- a/exporter/tar/export.go +++ b/exporter/tar/export.go @@ -7,6 +7,7 @@ import ( "time" "github.com/moby/buildkit/cache" + "github.com/moby/buildkit/client" "github.com/moby/buildkit/exporter" "github.com/moby/buildkit/exporter/containerimage/exptypes" "github.com/moby/buildkit/exporter/local" @@ -37,6 +38,7 @@ func (e *localExporter) Resolve(ctx context.Context, id int, opt map[string]stri li := &localExporterInstance{ localExporter: e, id: id, + attrs: opt, } _, err := li.opts.Load(opt) if err != nil { @@ -49,7 +51,8 @@ func (e *localExporter) Resolve(ctx context.Context, id int, opt map[string]stri type localExporterInstance struct { *localExporter - id int + id int + attrs map[string]string opts local.CreateFSOpts } @@ -62,6 +65,14 @@ func (e *localExporterInstance) Name() string { return "exporting to client tarball" } +func (e *localExporterInstance) Type() string { + return client.ExporterTar +} + +func (e *localExporterInstance) Attrs() map[string]string { + return e.attrs +} + func (e *localExporterInstance) Config() *exporter.Config { return exporter.NewConfig() } diff --git a/frontend/dockerfile/dockerfile_provenance_test.go b/frontend/dockerfile/dockerfile_provenance_test.go index 19de6a9e360a..02e4cf78de78 100644 --- a/frontend/dockerfile/dockerfile_provenance_test.go +++ b/frontend/dockerfile/dockerfile_provenance_test.go @@ -1369,6 +1369,7 @@ COPY bar bar2 break } require.Equal(t, ref, ev.Record.Ref) + require.Len(t, ev.Record.Exporters, 1) for _, prov := range ev.Record.Result.Attestations { if len(prov.Annotations) == 0 || prov.Annotations["in-toto.io/predicate-type"] != "https://slsa.dev/provenance/v0.2" { diff --git a/solver/llbsolver/solver.go b/solver/llbsolver/solver.go index 69085c6051c1..0d073fd1d27c 100644 --- a/solver/llbsolver/solver.go +++ b/solver/llbsolver/solver.go @@ -53,8 +53,6 @@ const ( ) type ExporterRequest struct { - Type string - Attrs map[string]string Exporters []exporter.ExporterInstance CacheExporters []RemoteCacheExporter } @@ -173,11 +171,11 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend CreatedAt: &st, } - if exp.Type != "" { - rec.Exporters = []*controlapi.Exporter{{ - Type: exp.Type, - Attrs: exp.Attrs, - }} + for _, e := range exp.Exporters { + rec.Exporters = append(rec.Exporters, &controlapi.Exporter{ + Type: e.Type(), + Attrs: e.Attrs(), + }) } if err := s.history.Update(ctx, &controlapi.BuildHistoryEvent{