@@ -17,7 +17,6 @@ import (
1717 "github.com/docker/buildx/util/ioset"
1818 "github.com/docker/buildx/util/progress"
1919 "github.com/google/shlex"
20- "github.com/moby/buildkit/client"
2120 "github.com/moby/buildkit/identity"
2221 "github.com/pkg/errors"
2322 "github.com/sirupsen/logrus"
@@ -63,8 +62,8 @@ func RunMonitor(ctx context.Context, curRef string, options *controllerapi.Build
6362 invokeForwarder := ioset .NewForwarder ()
6463 invokeForwarder .SetIn (& containerIn )
6564 m := & monitor {
66- controllerRef : newControllerRef ( c , curRef ) ,
67- invokeIO : invokeForwarder ,
65+ BuildxController : c ,
66+ invokeIO : invokeForwarder ,
6867 muxIO : ioset .NewMuxIO (ioset.In {
6968 Stdin : io .NopCloser (stdin ),
7069 Stdout : nopCloser {stdout },
@@ -77,6 +76,7 @@ func RunMonitor(ctx context.Context, curRef string, options *controllerapi.Build
7776 return "Switched IO\n "
7877 }),
7978 }
79+ m .ref .Store (curRef )
8080
8181 // Start container automatically
8282 fmt .Fprintf (stdout , "Launching interactive container. Press Ctrl-a-c to switch to monitor console\n " )
@@ -203,7 +203,8 @@ type readWriter struct {
203203}
204204
205205type monitor struct {
206- * controllerRef
206+ control.BuildxController
207+ ref atomic.Value
207208
208209 muxIO * ioset.MuxIO
209210 invokeIO * ioset.Forwarder
@@ -212,15 +213,15 @@ type monitor struct {
212213}
213214
214215func (m * monitor ) DisconnectSession (ctx context.Context , targetID string ) error {
215- return m .controllerRef . raw (). Disconnect (ctx , targetID )
216+ return m .Disconnect (ctx , targetID )
216217}
217218
218219func (m * monitor ) AttachSession (ref string ) {
219- m .controllerRef . ref .Store (ref )
220+ m .ref .Store (ref )
220221}
221222
222223func (m * monitor ) AttachedSessionID () string {
223- return m .controllerRef . ref .Load ().(string )
224+ return m .ref .Load ().(string )
224225}
225226
226227func (m * monitor ) Rollback (ctx context.Context , cfg controllerapi.InvokeConfig ) string {
@@ -298,87 +299,12 @@ func (m *monitor) invoke(ctx context.Context, pid string, cfg controllerapi.Invo
298299 defer invokeCancelAndDetachFn ()
299300 m .invokeCancel = invokeCancelAndDetachFn
300301
301- err := m .controllerRef . invoke (invokeCtx , pid , cfg , containerIn .Stdin , containerIn .Stdout , containerIn .Stderr )
302+ err := m .Invoke (invokeCtx , m . AttachedSessionID () , pid , cfg , containerIn .Stdin , containerIn .Stdout , containerIn .Stderr )
302303 close (waitInvokeDoneCh )
303304
304305 return err
305306}
306307
307- func newControllerRef (c control.BuildxController , ref string ) * controllerRef {
308- cr := & controllerRef {c : c }
309- cr .ref .Store (ref )
310- return cr
311- }
312-
313- type controllerRef struct {
314- c control.BuildxController
315- ref atomic.Value
316- }
317-
318- func (c * controllerRef ) raw () control.BuildxController {
319- return c .c
320- }
321-
322- func (c * controllerRef ) getRef () (string , error ) {
323- ref := c .ref .Load ()
324- if ref == "" {
325- return "" , errors .Errorf ("client is not attached to a session" )
326- }
327- return ref .(string ), nil
328- }
329-
330- func (c * controllerRef ) Build (ctx context.Context , options controllerapi.BuildOptions , in io.ReadCloser , progress progress.Writer ) (ref string , resp * client.SolveResponse , err error ) {
331- return c .c .Build (ctx , options , in , progress )
332- }
333-
334- func (c * controllerRef ) invoke (ctx context.Context , pid string , options controllerapi.InvokeConfig , ioIn io.ReadCloser , ioOut io.WriteCloser , ioErr io.WriteCloser ) error {
335- ref , err := c .getRef ()
336- if err != nil {
337- return err
338- }
339- return c .c .Invoke (ctx , ref , pid , options , ioIn , ioOut , ioErr )
340- }
341-
342- func (c * controllerRef ) Kill (ctx context.Context ) error {
343- return c .c .Kill (ctx )
344- }
345-
346- func (c * controllerRef ) List (ctx context.Context ) (refs []string , _ error ) {
347- return c .c .List (ctx )
348- }
349-
350- func (c * controllerRef ) ListProcesses (ctx context.Context ) (infos []* controllerapi.ProcessInfo , retErr error ) {
351- ref , err := c .getRef ()
352- if err != nil {
353- return nil , err
354- }
355- return c .c .ListProcesses (ctx , ref )
356- }
357-
358- func (c * controllerRef ) DisconnectProcess (ctx context.Context , pid string ) error {
359- ref , err := c .getRef ()
360- if err != nil {
361- return err
362- }
363- return c .c .DisconnectProcess (ctx , ref , pid )
364- }
365-
366- func (c * controllerRef ) Inspect (ctx context.Context ) (* controllerapi.InspectResponse , error ) {
367- ref , err := c .getRef ()
368- if err != nil {
369- return nil , err
370- }
371- return c .c .Inspect (ctx , ref )
372- }
373-
374- func (c * controllerRef ) Disconnect (ctx context.Context ) error {
375- ref , err := c .getRef ()
376- if err != nil {
377- return err
378- }
379- return c .c .Disconnect (ctx , ref )
380- }
381-
382308type nopCloser struct {
383309 io.Writer
384310}
0 commit comments