mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
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 <me@jedevc.com>
This commit is contained in:
parent
f5719f3017
commit
e11c5e3e96
@ -7,6 +7,8 @@ import (
|
|||||||
"github.com/docker/buildx/driver"
|
"github.com/docker/buildx/driver"
|
||||||
"github.com/docker/buildx/util/progress"
|
"github.com/docker/buildx/util/progress"
|
||||||
"github.com/moby/buildkit/client"
|
"github.com/moby/buildkit/client"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/backoff"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
@ -23,25 +25,11 @@ type tlsOpts struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
|
func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
|
||||||
for i := 0; ; i++ {
|
c, err := d.Client(ctx)
|
||||||
info, err := d.Info(ctx)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return c.Wait(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Info(ctx context.Context) (*driver.Info, error) {
|
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) {
|
func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
|
||||||
opts := []client.ClientOpt{}
|
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 {
|
if d.tlsOpts != nil {
|
||||||
opts = append(opts, []client.ClientOpt{
|
opts = append(opts, []client.ClientOpt{
|
||||||
client.WithServerConfig(d.tlsOpts.serverName, d.tlsOpts.caCert),
|
client.WithServerConfig(d.tlsOpts.serverName, d.tlsOpts.caCert),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user