Skip to content

Commit 1c6fc42

Browse files
committed
Sync with upstream
Signed-off-by: a-palchikov <deemok@gmail.com>
1 parent 998cb95 commit 1c6fc42

File tree

6 files changed

+375
-849
lines changed

6 files changed

+375
-849
lines changed

api/services/control/control.pb.go

Lines changed: 327 additions & 807 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@ func testSessionExporter(t *testing.T, sb integration.Sandbox) {
23672367
require.Equal(t, "foo", resp.Entries[1].Path)
23682368

23692369
exporterCalled = true
2370-
target.Add(filesync.WithFSSync(0, fixedWriteCloser(nopWriteCloser{outW})))
2370+
target.Add(filesync.WithFSSync("0", fixedWriteCloser(nopWriteCloser{outW})))
23712371
return []*exporter.ExporterRequest{
23722372
{
23732373
Type: ExporterOCI,

client/solve.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ import (
3535
)
3636

3737
type SolveOpt struct {
38-
Exports []ExportEntry
38+
Exports []ExportEntry
3939
EnableSessionExporter bool
40-
LocalDirs map[string]string // Deprecated: use LocalMounts
41-
LocalMounts map[string]fsutil.FS
42-
OCIStores map[string]content.Store
43-
SharedKey string
44-
Frontend string
45-
FrontendAttrs map[string]string
46-
FrontendInputs map[string]llb.State
47-
CacheExports []CacheOptionsEntry
48-
CacheImports []CacheOptionsEntry
49-
Session []session.Attachable
50-
AllowedEntitlements []string
40+
LocalDirs map[string]string // Deprecated: use LocalMounts
41+
LocalMounts map[string]fsutil.FS
42+
OCIStores map[string]content.Store
43+
SharedKey string
44+
Frontend string
45+
FrontendAttrs map[string]string
46+
FrontendInputs map[string]llb.State
47+
CacheExports []CacheOptionsEntry
48+
CacheImports []CacheOptionsEntry
49+
Session []session.Attachable
50+
AllowedEntitlements []string
5151
// When the session is custom-initialized, Init can be used to
5252
// set up the session for export automatically.
5353
SharedSession *session.Session // TODO: refactor to better session syncing

control/control.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package control
33
import (
44
"context"
55
"fmt"
6-
"io"
76
"runtime/trace"
87
"strconv"
98
"sync"
@@ -23,13 +22,11 @@ import (
2322
"github.com/moby/buildkit/client/llb"
2423
"github.com/moby/buildkit/cmd/buildkitd/config"
2524
controlgateway "github.com/moby/buildkit/control/gateway"
26-
"github.com/moby/buildkit/exporter"
2725
"github.com/moby/buildkit/exporter/containerimage/exptypes"
2826
"github.com/moby/buildkit/exporter/util/epoch"
2927
"github.com/moby/buildkit/frontend"
3028
"github.com/moby/buildkit/frontend/attestations"
3129
"github.com/moby/buildkit/session"
32-
"github.com/moby/buildkit/session/filesync"
3330
"github.com/moby/buildkit/session/grpchijack"
3431
containerdsnapshot "github.com/moby/buildkit/snapshot/containerd"
3532
"github.com/moby/buildkit/solver"
@@ -49,7 +46,6 @@ import (
4946
"github.com/moby/buildkit/worker"
5047
digest "github.com/opencontainers/go-digest"
5148
"github.com/pkg/errors"
52-
"github.com/tonistiigi/fsutil"
5349
sdktrace "go.opentelemetry.io/otel/sdk/trace"
5450
tracev1 "go.opentelemetry.io/proto/otlp/collector/trace/v1"
5551
"golang.org/x/sync/errgroup"
@@ -421,7 +417,7 @@ func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*
421417
}
422418
expis = append(expis, llbsolver.Exporter{
423419
ID: ex.ID,
424-
ExporterAPIs: newExporterAPIs(ex.ID),
420+
ExporterAPIs: llbsolver.NewExporterAPIs(ex.ID),
425421
ExporterInstance: expi,
426422
})
427423
}
@@ -786,23 +782,3 @@ func entitlementsFromPB(elems []string) []entitlements.Entitlement {
786782
}
787783
return clone
788784
}
789-
790-
func newExporterAPIs(id string) exporter.ExporterAPIs {
791-
apis := exporterAPIs{exporterID: id}
792-
return exporter.ExporterAPIs{
793-
CopyToCaller: apis.CopyToCaller,
794-
CopyFileWriter: apis.CopyFileWriter,
795-
}
796-
}
797-
798-
func (r exporterAPIs) CopyToCaller(ctx context.Context, fs fsutil.FS, c session.Caller, progress func(int, bool)) error {
799-
return filesync.CopyToCaller(ctx, fs, r.exporterID, c, progress)
800-
}
801-
802-
func (r exporterAPIs) CopyFileWriter(ctx context.Context, md map[string]string, c session.Caller) (io.WriteCloser, error) {
803-
return filesync.CopyFileWriter(ctx, md, r.exporterID, c)
804-
}
805-
806-
type exporterAPIs struct {
807-
exporterID string
808-
}

exporter/exporter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type ExporterInstance interface {
2929
Export(ctx context.Context, src *Source, inlineCache exptypes.InlineCache, sessionID string, apis ExporterAPIs) (map[string]string, DescriptorReference, error)
3030
}
3131

32+
// ExporterAPIs encapsulates the APIs for exporters that stream results to clients
3233
type ExporterAPIs struct {
3334
CopyFileWriter func(_ context.Context, md map[string]string, c session.Caller) (io.WriteCloser, error)
3435
CopyToCaller func(_ context.Context, fs fsutil.FS, c session.Caller, progress func(int, bool)) error

solver/llbsolver/solver.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"io"
78
"maps"
89
"os"
910
"strings"
@@ -30,6 +31,7 @@ import (
3031
"github.com/moby/buildkit/identity"
3132
"github.com/moby/buildkit/session"
3233
sessionexporter "github.com/moby/buildkit/session/exporter"
34+
"github.com/moby/buildkit/session/filesync"
3335
"github.com/moby/buildkit/solver"
3436
"github.com/moby/buildkit/solver/llbsolver/provenance"
3537
"github.com/moby/buildkit/solver/result"
@@ -45,6 +47,7 @@ import (
4547
"github.com/moby/buildkit/worker"
4648
digest "github.com/opencontainers/go-digest"
4749
"github.com/pkg/errors"
50+
"github.com/tonistiigi/fsutil"
4851
"golang.org/x/sync/errgroup"
4952
"google.golang.org/grpc/codes"
5053
"google.golang.org/protobuf/types/known/timestamppb"
@@ -691,7 +694,7 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro
691694
return exporterResponse, nil
692695
}
693696

694-
func (s *Solver) getSessionExporters(ctx context.Context, sessionID string, id int, inp *exporter.Source) ([]exporter.ExporterInstance, error) {
697+
func (s *Solver) getSessionExporters(ctx context.Context, sessionID string, id int, inp *exporter.Source) ([]Exporter, error) {
695698
timeoutCtx, cancel := context.WithCancelCause(ctx)
696699
timeoutCtx, _ = context.WithTimeoutCause(timeoutCtx, 5*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet
697700
defer func() { cancel(errors.WithStack(context.Canceled)) }()
@@ -729,17 +732,22 @@ func (s *Solver) getSessionExporters(ctx context.Context, sessionID string, id i
729732
return nil, err
730733
}
731734

732-
var out []exporter.ExporterInstance
735+
var out []Exporter
733736
for i, req := range res.Exporters {
734737
exp, err := w.Exporter(req.Type, s.sm)
735738
if err != nil {
736739
return nil, err
737740
}
738-
expi, err := exp.Resolve(ctx, id+i, req.Attrs)
741+
expi, err := exp.Resolve(ctx, req.Attrs)
739742
if err != nil {
740743
return nil, err
741744
}
742-
out = append(out, expi)
745+
id := fmt.Sprint(id + i)
746+
out = append(out, Exporter{
747+
ExporterInstance: expi,
748+
ExporterAPIs: NewExporterAPIs(id),
749+
ID: id,
750+
})
743751
}
744752
return out, nil
745753
}
@@ -1231,3 +1239,24 @@ func loadSourcePolicy(b solver.Builder) (*spb.Policy, error) {
12311239
}
12321240
return &srcPol, nil
12331241
}
1242+
1243+
// NewExporterAPIs creates a new exporter API for the specified id
1244+
func NewExporterAPIs(id string) exporter.ExporterAPIs {
1245+
apis := exporterAPIs{exporterID: id}
1246+
return exporter.ExporterAPIs{
1247+
CopyToCaller: apis.CopyToCaller,
1248+
CopyFileWriter: apis.CopyFileWriter,
1249+
}
1250+
}
1251+
1252+
func (r exporterAPIs) CopyToCaller(ctx context.Context, fs fsutil.FS, c session.Caller, progress func(int, bool)) error {
1253+
return filesync.CopyToCaller(ctx, fs, r.exporterID, c, progress)
1254+
}
1255+
1256+
func (r exporterAPIs) CopyFileWriter(ctx context.Context, md map[string]string, c session.Caller) (io.WriteCloser, error) {
1257+
return filesync.CopyFileWriter(ctx, md, r.exporterID, c)
1258+
}
1259+
1260+
type exporterAPIs struct {
1261+
exporterID string
1262+
}

0 commit comments

Comments
 (0)