Skip to content

Commit

Permalink
driver(docker): allow attaching additional headers to the client
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Sep 28, 2023
1 parent e6756d9 commit 082fa36
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type builderOpts struct {
name string
txn *store.Txn
contextPathHash string
meta map[string][]string
validate bool
}

Expand Down Expand Up @@ -59,6 +60,13 @@ func WithContextPathHash(contextPathHash string) Option {
}
}

// WithMeta sets additional headers for the client.
func WithMeta(meta map[string][]string) Option {
return func(b *Builder) {
b.opts.meta = meta
}
}

// WithSkippedValidation skips builder context validation.
func WithSkippedValidation() Option {
return func(b *Builder) {
Expand Down
2 changes: 1 addition & 1 deletion builder/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (b *Builder) LoadNodes(ctx context.Context, withData bool) (_ []Node, err e
}
}

d, err := driver.GetDriver(ctx, "buildx_buildkit_"+n.Name, factory, n.Endpoint, dockerapi, imageopt.Auth, kcc, n.Flags, n.Files, n.DriverOpts, n.Platforms, b.opts.contextPathHash)
d, err := driver.GetDriver(ctx, "buildx_buildkit_"+n.Name, factory, n.Endpoint, dockerapi, imageopt.Auth, kcc, n.Flags, n.Files, n.DriverOpts, n.Platforms, b.opts.meta, b.opts.contextPathHash)
if err != nil {
node.Err = err
return nil
Expand Down
2 changes: 1 addition & 1 deletion driver/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (d *Driver) Rm(ctx context.Context, force, rmVolume, rmDaemon bool) error {
func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
opts := []client.ClientOpt{
client.WithContextDialer(func(context.Context, string) (net.Conn, error) {
return d.DockerAPI.DialHijack(ctx, "/grpc", "h2c", nil)
return d.DockerAPI.DialHijack(ctx, "/grpc", "h2c", d.Meta)
}), client.WithSessionDialer(func(ctx context.Context, proto string, meta map[string][]string) (net.Conn, error) {
return d.DockerAPI.DialHijack(ctx, "/session", proto, meta)
}),
Expand Down
7 changes: 4 additions & 3 deletions driver/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ type InitConfig struct {
DriverOpts map[string]string
Auth Auth
Platforms []specs.Platform
// ContextPathHash can be used for determining pods in the driver instance
ContextPathHash string
Meta map[string][]string // Meta is used for passing additional headers to the client (only docker one atm)
ContextPathHash string // ContextPathHash can be used for determining pods in the driver instance
}

var drivers map[string]Factory
Expand Down Expand Up @@ -104,7 +104,7 @@ func GetFactory(name string, instanceRequired bool) (Factory, error) {
return nil, errors.Errorf("failed to find driver %q", name)
}

func GetDriver(ctx context.Context, name string, f Factory, endpointAddr string, api dockerclient.APIClient, auth Auth, kcc KubeClientConfig, flags []string, files map[string][]byte, do map[string]string, platforms []specs.Platform, contextPathHash string) (*DriverHandle, error) {
func GetDriver(ctx context.Context, name string, f Factory, endpointAddr string, api dockerclient.APIClient, auth Auth, kcc KubeClientConfig, flags []string, files map[string][]byte, do map[string]string, platforms []specs.Platform, meta map[string][]string, contextPathHash string) (*DriverHandle, error) {
ic := InitConfig{
EndpointAddr: endpointAddr,
DockerAPI: api,
Expand All @@ -116,6 +116,7 @@ func GetDriver(ctx context.Context, name string, f Factory, endpointAddr string,
Platforms: platforms,
ContextPathHash: contextPathHash,
Files: files,
Meta: meta,
}
if f == nil {
var err error
Expand Down

0 comments on commit 082fa36

Please sign in to comment.