mirror of https://github.com/docker/buildx.git
Merge pull request #2501 from tonistiigi/remote-client-cache
remote: ensure that client connection is not established twice
This commit is contained in:
commit
4be2259719
|
@ -7,6 +7,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/buildx/driver"
|
"github.com/docker/buildx/driver"
|
||||||
|
@ -14,6 +15,7 @@ import (
|
||||||
"github.com/docker/buildx/util/progress"
|
"github.com/docker/buildx/util/progress"
|
||||||
"github.com/moby/buildkit/client"
|
"github.com/moby/buildkit/client"
|
||||||
"github.com/moby/buildkit/client/connhelper"
|
"github.com/moby/buildkit/client/connhelper"
|
||||||
|
"github.com/moby/buildkit/util/tracing/delegated"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,6 +27,11 @@ type Driver struct {
|
||||||
// https://github.com/docker/docs/blob/main/content/build/drivers/remote.md
|
// https://github.com/docker/docs/blob/main/content/build/drivers/remote.md
|
||||||
*tlsOpts
|
*tlsOpts
|
||||||
defaultLoad bool
|
defaultLoad bool
|
||||||
|
|
||||||
|
// remote driver caches the client because its Bootstap/Info methods reuse it internally
|
||||||
|
clientOnce sync.Once
|
||||||
|
client *client.Client
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
type tlsOpts struct {
|
type tlsOpts struct {
|
||||||
|
@ -78,12 +85,18 @@ func (d *Driver) Rm(ctx context.Context, force, rmVolume, rmDaemon bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Client(ctx context.Context, opts ...client.ClientOpt) (*client.Client, error) {
|
func (d *Driver) Client(ctx context.Context, opts ...client.ClientOpt) (*client.Client, error) {
|
||||||
opts = append([]client.ClientOpt{
|
d.clientOnce.Do(func() {
|
||||||
client.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) {
|
opts = append([]client.ClientOpt{
|
||||||
return d.Dial(ctx)
|
client.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) {
|
||||||
}),
|
return d.Dial(ctx)
|
||||||
}, opts...)
|
}),
|
||||||
return client.New(ctx, "", opts...)
|
client.WithTracerDelegate(delegated.DefaultExporter),
|
||||||
|
}, opts...)
|
||||||
|
c, err := client.New(ctx, "", opts...)
|
||||||
|
d.client = c
|
||||||
|
d.err = err
|
||||||
|
})
|
||||||
|
return d.client, d.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Dial(ctx context.Context) (net.Conn, error) {
|
func (d *Driver) Dial(ctx context.Context) (net.Conn, error) {
|
||||||
|
|
Loading…
Reference in New Issue