Merge pull request #45224 from cpuguy83/move_bk_client
Move buildkit client opts to new package
This commit is contained in:
commit
328de8442d
2 changed files with 28 additions and 27 deletions
|
@ -1,27 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/moby/buildkit/client"
|
||||
)
|
||||
|
||||
// BuildkitClientOpts returns a list of buildkit client options which allows the
|
||||
// caller to use to create a buildkit client which will connect to the buildkit
|
||||
// API provided by the daemon.
|
||||
//
|
||||
// Example: bkclient.New(ctx, "", BuildkitClientOpts(c)...)
|
||||
func BuildkitClientOpts(c CommonAPIClient) []client.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 []client.ClientOpt{
|
||||
client.WithSessionDialer(session),
|
||||
client.WithContextDialer(grpc),
|
||||
}
|
||||
}
|
28
client/buildkit/buildkit.go
Normal file
28
client/buildkit/buildkit.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
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),
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue