Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

history: fix empty Exporters attribute #5017

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(possible follow-up) Maybe the Attrs and Config() can be combined somehow in the future. Atm not obvious why there are two similar sounding things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe a better approach is to change the solver.ExporterRequest to keep array of objects that keep type/attrs instead of raw ExporterInstance. Like it was previously with the keys that are now removed.

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
Loading