diff --git a/client/client_test.go b/client/client_test.go index fce54e58b1a34..8efa9a4410219 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -2937,6 +2937,7 @@ func testMultipleExporters(t *testing.T, sb integration.Sandbox) { break } require.Equal(t, ref, ev.Record.Ref) + require.Len(t, ev.Record.Exporters, 4) if workers.IsTestDockerd() { require.Len(t, ev.Record.Result.Results, 1) diff --git a/exporter/containerimage/export.go b/exporter/containerimage/export.go index ef4172e21b07d..afaa771ec19aa 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 @@ -187,6 +190,14 @@ func (e *imageExporterInstance) ID() int { } func (e *imageExporterInstance) Name() string { + return client.ExporterImage +} + +func (e *imageExporterInstance) Attrs() map[string]string { + return e.attrs +} + +func (e *imageExporterInstance) ProgressName() string { return "exporting to image" } diff --git a/exporter/exporter.go b/exporter/exporter.go index bbaf4b8a49a0b..12c2368734a2b 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -21,6 +21,8 @@ type Exporter interface { type ExporterInstance interface { ID() int Name() string + Attrs() map[string]string + ProgressName() string Config() *Config 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 b0426a4d412d7..f9e95092056d3 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 } @@ -60,6 +63,14 @@ func (e *localExporterInstance) ID() int { } func (e *localExporterInstance) Name() string { + return client.ExporterLocal +} + +func (e *localExporterInstance) Attrs() map[string]string { + return e.attrs +} + +func (e *localExporterInstance) ProgressName() string { return "exporting to client directory" } diff --git a/exporter/oci/export.go b/exporter/oci/export.go index 3748f536caa4c..97c51906694ee 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 @@ -112,6 +115,14 @@ func (e *imageExporterInstance) ID() int { } func (e *imageExporterInstance) Name() string { + return string(e.opt.Variant) +} + +func (e *imageExporterInstance) Attrs() map[string]string { + return e.attrs +} + +func (e *imageExporterInstance) ProgressName() string { return fmt.Sprintf("exporting to %s image format", e.opt.Variant) } diff --git a/exporter/tar/export.go b/exporter/tar/export.go index 36b5d1cf01548..6da4d1a3c723f 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 } @@ -59,6 +62,14 @@ func (e *localExporterInstance) ID() int { } func (e *localExporterInstance) Name() string { + return client.ExporterTar +} + +func (e *localExporterInstance) Attrs() map[string]string { + return e.attrs +} + +func (e *localExporterInstance) ProgressName() string { return "exporting to client tarball" } diff --git a/frontend/dockerfile/dockerfile_provenance_test.go b/frontend/dockerfile/dockerfile_provenance_test.go index 19de6a9e360a1..02e4cf78de786 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 69085c6051c12..df2dd5be54d47 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.Name(), + Attrs: e.Attrs(), + }) } if err := s.history.Update(ctx, &controlapi.BuildHistoryEvent{ @@ -750,8 +748,8 @@ func (s *Solver) runExporters(ctx context.Context, exporters []exporter.Exporter i, exp := i, exp eg.Go(func() error { id := fmt.Sprint(job.SessionID, "-export-", i) - return inBuilderContext(ctx, job, exp.Name(), id, func(ctx context.Context, _ session.Group) error { - span, ctx := tracing.StartSpan(ctx, exp.Name()) + return inBuilderContext(ctx, job, exp.ProgressName(), id, func(ctx context.Context, _ session.Group) error { + span, ctx := tracing.StartSpan(ctx, exp.ProgressName()) defer span.End() if i == 0 && len(warnings) > 0 {