Skip to content

Commit

Permalink
Merge pull request #5017 from crazy-max/fix-history-exporters
Browse files Browse the repository at this point in the history
history: fix empty Exporters attribute
  • Loading branch information
tonistiigi authored Jun 11, 2024
2 parents eed17a4 + 6b6fa9d commit 4d9a4e5
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 13 deletions.
2 changes: 2 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2940,13 +2940,15 @@ 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 {
require.Equal(t, images.MediaTypeDockerSchema2Manifest, ev.Record.Result.Results[0].MediaType)
}
} 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)
}
Expand Down
1 change: 1 addition & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion exporter/containerimage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
13 changes: 12 additions & 1 deletion exporter/local/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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()
}
Expand Down
17 changes: 14 additions & 3 deletions exporter/oci/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,8 +35,8 @@ import (
type ExporterVariant string

const (
VariantOCI = "oci"
VariantDocker = "docker"
VariantOCI = client.ExporterOCI
VariantDocker = client.ExporterDocker
)

const (
Expand All @@ -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{
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
13 changes: 12 additions & 1 deletion exporter/tar/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions frontend/dockerfile/dockerfile_provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
12 changes: 5 additions & 7 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ const (
)

type ExporterRequest struct {
Type string
Attrs map[string]string
Exporters []exporter.ExporterInstance
CacheExporters []RemoteCacheExporter
}
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 4d9a4e5

Please sign in to comment.