moby/client/buildkit/buildkit.go
Brian Goff 713c9280ca Move buildkit client opts to new package
Not everyone who imports the client wants to pull in all of buildkit, so
move it to a separate package.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-03-29 16:59:44 +00:00

28 lines
805 B
Go

package buildkit
import (
"context"
"net"
"github.com/docker/docker/client"
bkclient "github.com/moby/buildkit/client"
)
// ClientOpts returns a list of buildkit client options which allows the
// caller to create a buildkit client which will connect to the buildkit
// API provided by the daemon.
//
// Example: bkclient.New(ctx, "", ClientOpts(c)...)
func ClientOpts(c client.CommonAPIClient) []bkclient.ClientOpt {
session := func(ctx context.Context, proto string, meta map[string][]string) (net.Conn, error) {
return c.DialHijack(ctx, "/session", proto, meta)
}
grpc := func(ctx context.Context, _ string) (net.Conn, error) {
return c.DialHijack(ctx, "/grpc", "h2c", nil)
}
return []bkclient.ClientOpt{
bkclient.WithSessionDialer(session),
bkclient.WithContextDialer(grpc),
}
}