88
99 "github.com/containerd/platforms"
1010 "github.com/goccy/go-yaml"
11- "github.com/moby/buildkit/client/llb"
1211 "github.com/moby/buildkit/frontend/dockerui"
1312 gwclient "github.com/moby/buildkit/frontend/gateway/client"
1413 "github.com/project-dalec/dalec"
@@ -39,15 +38,8 @@ func (err *noSuchHandlerError) Error() string {
3938 return fmt .Sprintf ("no such handler for target %q: available targets: %s" , err .Target , strings .Join (err .Available , ", " ))
4039}
4140
42- // CurrentFrontend is an interface typically implemented by a [gwclient.Client].
43- // This is used to get the rootfs of the current frontend.
44- type CurrentFrontend interface {
45- CurrentFrontend () (* llb.State , error )
46- }
47-
4841var (
4942 _ gwclient.Client = (* clientWithCustomOpts )(nil )
50- _ CurrentFrontend = (* clientWithCustomOpts )(nil )
5143)
5244
5345type clientWithCustomOpts struct {
@@ -59,20 +51,16 @@ func (d *clientWithCustomOpts) BuildOpts() gwclient.BuildOpts {
5951 return d .opts
6052}
6153
62- func (d * clientWithCustomOpts ) CurrentFrontend () (* llb.State , error ) {
63- return d .Client .(CurrentFrontend ).CurrentFrontend ()
64- }
65-
66- func setClientOptOption (client gwclient.Client , extraOpts map [string ]string ) * clientWithCustomOpts {
54+ func setClientOptOption (client gwclient.Client , extraOpts map [string ]string ) gwclient.Client {
6755 opts := client .BuildOpts ()
6856
6957 for key , value := range extraOpts {
7058 opts .Opts [key ] = value
7159 }
72- return & clientWithCustomOpts {
60+ return withCurrentFrontend ( client , & clientWithCustomOpts {
7361 Client : client ,
7462 opts : opts ,
75- }
63+ })
7664}
7765
7866func maybeSetDalecTargetKey (client gwclient.Client , key string ) gwclient.Client {
@@ -82,13 +70,13 @@ func maybeSetDalecTargetKey(client gwclient.Client, key string) gwclient.Client
8270 return client
8371 }
8472
85- // optimization to help prevent unnecessary grpc requests
73+ // Optimization to help prevent unnecessary grpc requests.
8674 // The gateway client will make a grpc request to get the build opts from the gateway.
8775 // This just caches those opts locally.
8876 // If the client is already a clientWithCustomOpts, then the opts are already cached.
8977 if _ , ok := client .(* clientWithCustomOpts ); ! ok {
9078 // this forces the client to use our cached opts from above
91- client = & clientWithCustomOpts {opts : opts , Client : client }
79+ client = withCurrentFrontend ( client , & clientWithCustomOpts {opts : opts , Client : client })
9280 }
9381 return setClientOptOption (client , map [string ]string {keyTopLevelTarget : key , "build-arg:" + dalec .KeyDalecTarget : key })
9482}
0 commit comments