Skip to content

Commit

Permalink
Merge pull request #59 from earthly/brandon/http-proxy
Browse files Browse the repository at this point in the history
Allows option for client to use grpc default dialer. The builtin dialer in gRPC has support for things like HTTP connect proxy which we need to support BYOC satellites in some environments. Buildkit was previously forcing it's own dialer implementation.
  • Loading branch information
brandonSc authored May 15, 2024
2 parents 594835b + e163acd commit 531b303
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 531b303

Please sign in to comment.