From e11c5e3e964275d21af5c277f121939e87c46dfa Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 12 Jul 2023 11:36:03 +0100 Subject: [PATCH] remote: use buildkit's client.Wait method to bootstrap This native implementation uses GRPC level waiting, instead of starting a busy loop. We also a manual max backoff of one second to improve responsiveness. Signed-off-by: Justin Chadwell --- driver/remote/driver.go | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/driver/remote/driver.go b/driver/remote/driver.go index fa5cfcc5..27ffd169 100644 --- a/driver/remote/driver.go +++ b/driver/remote/driver.go @@ -7,6 +7,8 @@ import ( "github.com/docker/buildx/driver" "github.com/docker/buildx/util/progress" "github.com/moby/buildkit/client" + "google.golang.org/grpc" + "google.golang.org/grpc/backoff" ) type Driver struct { @@ -23,25 +25,11 @@ type tlsOpts struct { } func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error { - for i := 0; ; i++ { - info, err := d.Info(ctx) - if err != nil { - return err - } - if info.Status != driver.Inactive { - return nil - } - - select { - case <-ctx.Done(): - return ctx.Err() - default: - if i > 10 { - i = 10 - } - time.Sleep(time.Duration(i) * time.Second) - } + c, err := d.Client(ctx) + if err != nil { + return err } + return c.Wait(ctx) } func (d *Driver) Info(ctx context.Context) (*driver.Info, error) { @@ -77,6 +65,13 @@ func (d *Driver) Rm(ctx context.Context, force, rmVolume, rmDaemon bool) error { func (d *Driver) Client(ctx context.Context) (*client.Client, error) { opts := []client.ClientOpt{} + + backoffConfig := backoff.DefaultConfig + backoffConfig.MaxDelay = 1 * time.Second + opts = append(opts, client.WithGRPCDialOption( + grpc.WithConnectParams(grpc.ConnectParams{Backoff: backoffConfig}), + )) + if d.tlsOpts != nil { opts = append(opts, []client.ClientOpt{ client.WithServerConfig(d.tlsOpts.serverName, d.tlsOpts.caCert),