Skip to content

Commit 4d9a4e5

Browse files
authored
Merge pull request moby#5017 from crazy-max/fix-history-exporters
history: fix empty Exporters attribute
2 parents eed17a4 + 6b6fa9d commit 4d9a4e5

File tree

9 files changed

+61
-13
lines changed

9 files changed

+61
-13
lines changed

client/client_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,13 +2940,15 @@ func testMultipleExporters(t *testing.T, sb integration.Sandbox) {
29402940

29412941
if workers.IsTestDockerd() {
29422942
require.Len(t, ev.Record.Result.Results, 1)
2943+
require.Len(t, ev.Record.Exporters, 5)
29432944
if workers.IsTestDockerdMoby(sb) {
29442945
require.Equal(t, images.MediaTypeDockerSchema2Config, ev.Record.Result.Results[0].MediaType)
29452946
} else {
29462947
require.Equal(t, images.MediaTypeDockerSchema2Manifest, ev.Record.Result.Results[0].MediaType)
29472948
}
29482949
} else {
29492950
require.Len(t, ev.Record.Result.Results, 2)
2951+
require.Len(t, ev.Record.Exporters, 6)
29502952
require.Equal(t, images.MediaTypeDockerSchema2Manifest, ev.Record.Result.Results[0].MediaType)
29512953
require.Equal(t, ocispecs.MediaTypeImageManifest, ev.Record.Result.Results[1].MediaType)
29522954
}

control/control.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*
372372
if err != nil {
373373
return nil, err
374374
}
375+
bklog.G(ctx).Debugf("resolve exporter %s with %v", ex.Type, ex.Attrs)
375376
expi, err := exp.Resolve(ctx, i, ex.Attrs)
376377
if err != nil {
377378
return nil, err

exporter/containerimage/export.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
cerrdefs "github.com/containerd/errdefs"
2121
"github.com/moby/buildkit/cache"
2222
cacheconfig "github.com/moby/buildkit/cache/config"
23+
"github.com/moby/buildkit/client"
2324
"github.com/moby/buildkit/exporter"
2425
"github.com/moby/buildkit/exporter/containerimage/exptypes"
2526
"github.com/moby/buildkit/session"
@@ -68,6 +69,7 @@ func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]stri
6869
i := &imageExporterInstance{
6970
imageExporter: e,
7071
id: id,
72+
attrs: opt,
7173
opts: ImageCommitOpts{
7274
RefCfg: cacheconfig.RefConfig{
7375
Compression: compression.New(compression.Default),
@@ -168,7 +170,8 @@ func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]stri
168170

169171
type imageExporterInstance struct {
170172
*imageExporter
171-
id int
173+
id int
174+
attrs map[string]string
172175

173176
opts ImageCommitOpts
174177
push bool
@@ -194,6 +197,14 @@ func (e *imageExporterInstance) Config() *exporter.Config {
194197
return exporter.NewConfigWithCompression(e.opts.RefCfg.Compression)
195198
}
196199

200+
func (e *imageExporterInstance) Type() string {
201+
return client.ExporterImage
202+
}
203+
204+
func (e *imageExporterInstance) Attrs() map[string]string {
205+
return e.attrs
206+
}
207+
197208
func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source, inlineCache exptypes.InlineCache, sessionID string) (_ map[string]string, descref exporter.DescriptorReference, err error) {
198209
src = src.Clone()
199210
if src.Metadata == nil {

exporter/exporter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type ExporterInstance interface {
2222
ID() int
2323
Name() string
2424
Config() *Config
25+
Type() string
26+
Attrs() map[string]string
2527
Export(ctx context.Context, src *Source, inlineCache exptypes.InlineCache, sessionID string) (map[string]string, DescriptorReference, error)
2628
}
2729

exporter/local/export.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/moby/buildkit/cache"
11+
"github.com/moby/buildkit/client"
1112
"github.com/moby/buildkit/exporter"
1213
"github.com/moby/buildkit/exporter/containerimage/exptypes"
1314
"github.com/moby/buildkit/exporter/util/epoch"
@@ -38,6 +39,7 @@ func New(opt Opt) (exporter.Exporter, error) {
3839
func (e *localExporter) Resolve(ctx context.Context, id int, opt map[string]string) (exporter.ExporterInstance, error) {
3940
i := &localExporterInstance{
4041
id: id,
42+
attrs: opt,
4143
localExporter: e,
4244
}
4345
_, err := i.opts.Load(opt)
@@ -50,7 +52,8 @@ func (e *localExporter) Resolve(ctx context.Context, id int, opt map[string]stri
5052

5153
type localExporterInstance struct {
5254
*localExporter
53-
id int
55+
id int
56+
attrs map[string]string
5457

5558
opts CreateFSOpts
5659
}
@@ -63,6 +66,14 @@ func (e *localExporterInstance) Name() string {
6366
return "exporting to client directory"
6467
}
6568

69+
func (e *localExporterInstance) Type() string {
70+
return client.ExporterLocal
71+
}
72+
73+
func (e *localExporterInstance) Attrs() map[string]string {
74+
return e.attrs
75+
}
76+
6677
func (e *localExporter) Config() *exporter.Config {
6778
return exporter.NewConfig()
6879
}

exporter/oci/export.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/distribution/reference"
1515
"github.com/moby/buildkit/cache"
1616
cacheconfig "github.com/moby/buildkit/cache/config"
17+
"github.com/moby/buildkit/client"
1718
"github.com/moby/buildkit/exporter"
1819
"github.com/moby/buildkit/exporter/containerimage"
1920
"github.com/moby/buildkit/exporter/containerimage/exptypes"
@@ -34,8 +35,8 @@ import (
3435
type ExporterVariant string
3536

3637
const (
37-
VariantOCI = "oci"
38-
VariantDocker = "docker"
38+
VariantOCI = client.ExporterOCI
39+
VariantDocker = client.ExporterDocker
3940
)
4041

4142
const (
@@ -62,6 +63,7 @@ func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]stri
6263
i := &imageExporterInstance{
6364
imageExporter: e,
6465
id: id,
66+
attrs: opt,
6567
tar: true,
6668
opts: containerimage.ImageCommitOpts{
6769
RefCfg: cacheconfig.RefConfig{
@@ -100,7 +102,8 @@ func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]stri
100102

101103
type imageExporterInstance struct {
102104
*imageExporter
103-
id int
105+
id int
106+
attrs map[string]string
104107

105108
opts containerimage.ImageCommitOpts
106109
tar bool
@@ -115,6 +118,14 @@ func (e *imageExporterInstance) Name() string {
115118
return fmt.Sprintf("exporting to %s image format", e.opt.Variant)
116119
}
117120

121+
func (e *imageExporterInstance) Type() string {
122+
return string(e.opt.Variant)
123+
}
124+
125+
func (e *imageExporterInstance) Attrs() map[string]string {
126+
return e.attrs
127+
}
128+
118129
func (e *imageExporterInstance) Config() *exporter.Config {
119130
return exporter.NewConfigWithCompression(e.opts.RefCfg.Compression)
120131
}

exporter/tar/export.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/moby/buildkit/cache"
10+
"github.com/moby/buildkit/client"
1011
"github.com/moby/buildkit/exporter"
1112
"github.com/moby/buildkit/exporter/containerimage/exptypes"
1213
"github.com/moby/buildkit/exporter/local"
@@ -37,6 +38,7 @@ func (e *localExporter) Resolve(ctx context.Context, id int, opt map[string]stri
3738
li := &localExporterInstance{
3839
localExporter: e,
3940
id: id,
41+
attrs: opt,
4042
}
4143
_, err := li.opts.Load(opt)
4244
if err != nil {
@@ -49,7 +51,8 @@ func (e *localExporter) Resolve(ctx context.Context, id int, opt map[string]stri
4951

5052
type localExporterInstance struct {
5153
*localExporter
52-
id int
54+
id int
55+
attrs map[string]string
5356

5457
opts local.CreateFSOpts
5558
}
@@ -62,6 +65,14 @@ func (e *localExporterInstance) Name() string {
6265
return "exporting to client tarball"
6366
}
6467

68+
func (e *localExporterInstance) Type() string {
69+
return client.ExporterTar
70+
}
71+
72+
func (e *localExporterInstance) Attrs() map[string]string {
73+
return e.attrs
74+
}
75+
6576
func (e *localExporterInstance) Config() *exporter.Config {
6677
return exporter.NewConfig()
6778
}

frontend/dockerfile/dockerfile_provenance_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,7 @@ COPY bar bar2
13691369
break
13701370
}
13711371
require.Equal(t, ref, ev.Record.Ref)
1372+
require.Len(t, ev.Record.Exporters, 1)
13721373

13731374
for _, prov := range ev.Record.Result.Attestations {
13741375
if len(prov.Annotations) == 0 || prov.Annotations["in-toto.io/predicate-type"] != "https://slsa.dev/provenance/v0.2" {

solver/llbsolver/solver.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ const (
5353
)
5454

5555
type ExporterRequest struct {
56-
Type string
57-
Attrs map[string]string
5856
Exporters []exporter.ExporterInstance
5957
CacheExporters []RemoteCacheExporter
6058
}
@@ -173,11 +171,11 @@ func (s *Solver) recordBuildHistory(ctx context.Context, id string, req frontend
173171
CreatedAt: &st,
174172
}
175173

176-
if exp.Type != "" {
177-
rec.Exporters = []*controlapi.Exporter{{
178-
Type: exp.Type,
179-
Attrs: exp.Attrs,
180-
}}
174+
for _, e := range exp.Exporters {
175+
rec.Exporters = append(rec.Exporters, &controlapi.Exporter{
176+
Type: e.Type(),
177+
Attrs: e.Attrs(),
178+
})
181179
}
182180

183181
if err := s.history.Update(ctx, &controlapi.BuildHistoryEvent{

0 commit comments

Comments
 (0)