client: Add buildkit ClientOpts
This adds a function to the client package which can be used to create a buildkit client from our moby client. Example: ```go package main import ( "context" "github.com/moby/moby/client" bkclient "github.com/moby/buildkit/client" ) func main() { c := client.NewWithOpts() bc, _ := bkclient.New(context.Background(), "" client.BuildkitClientOpts(c), ) // ... } ``` Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
d7e6e33d07
commit
0fa7a4e3b4
1 changed files with 27 additions and 0 deletions
27
client/buildkit.go
Normal file
27
client/buildkit.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
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),
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue