@@ -9,12 +9,14 @@ import (
99 "github.com/moby/buildkit/frontend/gateway/grpcclient"
1010 gatewayapi "github.com/moby/buildkit/frontend/gateway/pb"
1111 "github.com/moby/buildkit/session"
12+ "github.com/moby/buildkit/session/exporter"
13+ "github.com/moby/buildkit/session/exporter/exporterprovider"
1214 "github.com/moby/buildkit/util/apicaps"
1315 "github.com/pkg/errors"
1416 "google.golang.org/grpc"
1517)
1618
17- func (c * Client ) Build (ctx context.Context , opt SolveOpt , product string , buildFunc gateway.BuildFunc , statusChan chan * SolveStatus ) (* SolveResponse , error ) {
19+ func (c * Client ) BuildExport (ctx context.Context , opt SolveOpt , product string , buildFunc gateway.BuildFunc , exportFunc gateway. ExportFunc , statusChan chan * SolveStatus ) (* SolveResponse , error ) {
1820 defer func () {
1921 if statusChan != nil {
2022 close (statusChan )
@@ -42,21 +44,35 @@ func (c *Client) Build(ctx context.Context, opt SolveOpt, product string, buildF
4244 })
4345 }
4446
47+ var g grpcclient.GrpcClient
48+ if exportFunc != nil {
49+ opt .EnableSessionExporter = true
50+ exporter := exporterprovider .New (func (ctx context.Context , _ map [string ][]byte , _ []string ) ([]* exporter.ExporterRequest , error ) {
51+ if g == nil {
52+ return nil , errors .New ("no build session found for export" )
53+ }
54+ return nil , g .Export (ctx , c .conn , exportFunc )
55+ })
56+ opt .Session = append (opt .Session , exporter )
57+ }
58+
4559 cb := func (ref string , s * session.Session , opts map [string ]string ) error {
4660 if feOpts == nil {
4761 feOpts = map [string ]string {}
4862 }
4963 maps .Copy (feOpts , opts )
5064 gwClient := c .gatewayClientForBuild (ref )
51- g , err := grpcclient .New (ctx , feOpts , s .ID (), product , gwClient , gworkers )
65+ var err error
66+ g , err = grpcclient .New (ctx , feOpts , s .ID (), product , gwClient , gworkers )
5267 if err != nil {
5368 return err
5469 }
5570
5671 caps := g .BuildOpts ().Caps
5772 gwClient .caps = & caps
5873
59- if err := g .Run (ctx , buildFunc ); err != nil {
74+ err = g .Build (ctx , buildFunc )
75+ if err != nil {
6076 return errors .Wrap (err , "failed to run Build function" )
6177 }
6278 return nil
@@ -65,6 +81,10 @@ func (c *Client) Build(ctx context.Context, opt SolveOpt, product string, buildF
6581 return c .solve (ctx , nil , cb , opt , statusChan )
6682}
6783
84+ func (c * Client ) Build (ctx context.Context , opt SolveOpt , product string , buildFunc gateway.BuildFunc , statusChan chan * SolveStatus ) (* SolveResponse , error ) {
85+ return c .BuildExport (ctx , opt , product , buildFunc , nil , statusChan )
86+ }
87+
6888func (c * Client ) gatewayClientForBuild (buildid string ) * gatewayClientForBuild {
6989 g := gatewayapi .NewLLBBridgeClient (c .conn )
7090 return & gatewayClientForBuild {
@@ -138,6 +158,11 @@ func (g *gatewayClientForBuild) Evaluate(ctx context.Context, in *gatewayapi.Eva
138158 return g .gateway .Evaluate (ctx , in , opts ... )
139159}
140160
161+ func (g * gatewayClientForBuild ) GetRemote (ctx context.Context , in * gatewayapi.GetRemoteRequest , opts ... grpc.CallOption ) (* gatewayapi.GetRemoteResponse , error ) {
162+ ctx = buildid .AppendToOutgoingContext (ctx , g .buildID )
163+ return g .gateway .GetRemote (ctx , in , opts ... )
164+ }
165+
141166func (g * gatewayClientForBuild ) Ping (ctx context.Context , in * gatewayapi.PingRequest , opts ... grpc.CallOption ) (* gatewayapi.PongResponse , error ) {
142167 ctx = buildid .AppendToOutgoingContext (ctx , g .buildID )
143168 return g .gateway .Ping (ctx , in , opts ... )
@@ -148,6 +173,11 @@ func (g *gatewayClientForBuild) Return(ctx context.Context, in *gatewayapi.Retur
148173 return g .gateway .Return (ctx , in , opts ... )
149174}
150175
176+ func (g * gatewayClientForBuild ) GetReturn (ctx context.Context , in * gatewayapi.GetReturnRequest , opts ... grpc.CallOption ) (* gatewayapi.GetReturnResponse , error ) {
177+ ctx = buildid .AppendToOutgoingContext (ctx , g .buildID )
178+ return g .gateway .GetReturn (ctx , in , opts ... )
179+ }
180+
151181func (g * gatewayClientForBuild ) Inputs (ctx context.Context , in * gatewayapi.InputsRequest , opts ... grpc.CallOption ) (* gatewayapi.InputsResponse , error ) {
152182 if g .caps != nil {
153183 if err := g .caps .Supports (gatewayapi .CapFrontendInputs ); err != nil {
0 commit comments