Skip to content

Commit 3b3cf9c

Browse files
Merge pull request #46 from depot/fast-connect
2 parents b56fbbd + a3330a4 commit 3b3cf9c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pkg/buildxdriver/driver.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package buildxdriver
33
import (
44
"context"
55
"log"
6+
"net"
67
"os"
8+
"strings"
79
"time"
810

911
"github.com/depot/cli/pkg/api"
@@ -82,7 +84,8 @@ func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
8284
defer cancel()
8385

8486
return progress.Wrap("[depot] connecting to "+d.builder.Platform+" builder", l, func(sub progress.SubLogger) error {
85-
for i := 0; ; i++ {
87+
for i := 0; i < 120; i++ {
88+
8689
info, err := d.Info(ctx)
8790
if err != nil {
8891
return err
@@ -100,12 +103,11 @@ func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error {
100103
case <-ctx.Done():
101104
return ctx.Err()
102105
default:
103-
if i > 10 {
104-
i = 10
105-
}
106-
time.Sleep(time.Duration(i) * time.Second)
106+
time.Sleep(1 * time.Second)
107107
}
108108
}
109+
110+
return errors.New("timed out connecting to builder")
109111
})
110112
}
111113

@@ -132,6 +134,11 @@ func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
132134
opts = append(opts, client.WithCredentials(d.tlsOpts.serverName, d.tlsOpts.caCert, d.tlsOpts.cert, d.tlsOpts.key))
133135
}
134136

137+
opts = append(opts, client.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
138+
addr = strings.TrimPrefix(addr, "tcp://")
139+
return net.Dial("tcp", addr)
140+
}))
141+
135142
return client.New(ctx, d.builderInfo.Addr, opts...)
136143
}
137144

0 commit comments

Comments
 (0)