diff --git a/client/client.go b/client/client.go index c590ba8ab..49514fdd1 100644 --- a/client/client.go +++ b/client/client.go @@ -52,6 +52,7 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error grpc.WithDefaultCallOptions(grpc_retry.WithBackoff(grpc_retry.BackoffExponentialWithJitter(10*time.Millisecond, 0.1))), //earthly } needDialer := true + useDefaultDialer := false // earthly-specific var unary []grpc.UnaryClientInterceptor var stream []grpc.StreamClientInterceptor @@ -94,6 +95,11 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error headersKV = h.kv } + // earthly-specific + if _, ok := o.(*withDefaultGRPCDialer); ok { + useDefaultDialer = true + } + if opt, ok := o.(*withGRPCDialOption); ok { customDialOptions = append(customDialOptions, opt.opt) } @@ -121,7 +127,7 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error stream = append(stream, otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(tracerProvider), otelgrpc.WithPropagators(propagators))) } - if needDialer { + if needDialer && !useDefaultDialer { dialFn, err := resolveDialer(address) if err != nil { return nil, err @@ -164,6 +170,14 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error gopts = append(gopts, grpc.WithChainStreamInterceptor(stream...)) gopts = append(gopts, customDialOptions...) + // earthly-specific + if useDefaultDialer { + split := strings.Split(address, "://") + if len(split) > 0 { + address = split[1] + } + } + conn, err := grpc.DialContext(ctx, address, gopts...) if err != nil { return nil, errors.Wrapf(err, "failed to dial %q . make sure buildkitd is running", address) diff --git a/client/client_earthly.go b/client/client_earthly.go index d45b8a312..4c2f788af 100644 --- a/client/client_earthly.go +++ b/client/client_earthly.go @@ -32,3 +32,14 @@ func headersStreamInterceptor(kv ...string) grpc.StreamClientInterceptor { return streamer(ctx, desc, cc, method, opts...) } } + +// WithDefaultGRPCDialer triggers the internal gRPC dialer to be used instead of the buildkit default. +// This can be important when buildkit server is behind an HTTP connect proxy, +// since the default dialer in gRPC already knows how to use those. +func WithDefaultGRPCDialer() ClientOpt { + return &withDefaultGRPCDialer{} +} + +type withDefaultGRPCDialer struct{} + +func (*withDefaultGRPCDialer) isClientOpt() {}