Przeglądaj źródła

Merge pull request #45203 from cpuguy83/client_add_buildkit_helper

client: Add buildkit ClientOpts
Sebastiaan van Stijn 2 lat temu
rodzic
commit
cba6f2d426
1 zmienionych plików z 27 dodań i 0 usunięć
  1. 27 0
      client/buildkit.go

+ 27 - 0
client/buildkit.go

@@ -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),
+	}
+}