Skip to content

Commit

Permalink
feat: allow option for client to use grpc dialer
Browse files Browse the repository at this point in the history
Buildkit has a custom `resolveDialer` dailer, that does not support HTTP proxy.
This adds the ability for a client to enable the default gRPC dialer, which
allows support for HTTP.
  • Loading branch information
brandonSc authored and mikejholly committed May 16, 2024
1 parent 850d6e6 commit be3e419
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions client/client_earthly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

0 comments on commit be3e419

Please sign in to comment.