-
Notifications
You must be signed in to change notification settings - Fork 617
Add support for native grpc on the docker socket #3369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,12 @@ import ( | |
| "strings" | ||
| "sync" | ||
|
|
||
| "github.com/docker/buildx/driver" | ||
| "github.com/docker/buildx/util/progress" | ||
| "github.com/moby/buildkit/client" | ||
| dockerclient "github.com/moby/moby/client" | ||
| "github.com/pkg/errors" | ||
|
|
||
| "github.com/docker/buildx/driver" | ||
| "github.com/docker/buildx/util/progress" | ||
| ) | ||
|
|
||
| type Driver struct { | ||
|
|
@@ -64,14 +65,39 @@ func (d *Driver) Dial(ctx context.Context) (net.Conn, error) { | |
| } | ||
|
|
||
| func (d *Driver) Client(ctx context.Context, opts ...client.ClientOpt) (*client.Client, error) { | ||
| opts = append([]client.ClientOpt{ | ||
| client.WithContextDialer(func(context.Context, string) (net.Conn, error) { | ||
| return d.Dial(ctx) | ||
| }), client.WithSessionDialer(func(ctx context.Context, proto string, meta map[string][]string) (net.Conn, error) { | ||
| return d.DockerAPI.DialHijack(ctx, "/session", proto, meta) | ||
| }), | ||
| }, opts...) | ||
| return client.New(ctx, "", opts...) | ||
| c, _, err := d.client(ctx, opts...) | ||
| return c, err | ||
| } | ||
|
|
||
| func (d *Driver) client(ctx context.Context, opts ...client.ClientOpt) (*client.Client, []*client.WorkerInfo, error) { | ||
| var ( | ||
| c, err = client.New(ctx, d.DockerAPI.DaemonHost(), opts...) | ||
| workers []*client.WorkerInfo | ||
| ) | ||
| if err == nil { | ||
| workers, err = c.ListWorkers(ctx) | ||
| if err != nil { | ||
| c.Close() | ||
| } | ||
| } | ||
| if err != nil { | ||
| opts = append([]client.ClientOpt{ | ||
| client.WithContextDialer(func(context.Context, string) (net.Conn, error) { | ||
| return d.Dial(ctx) | ||
|
Comment on lines
+83
to
+86
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add some comment to describe that this is the fallback for the legacy approach @akerouanton (Which could include a link to the moby PR), so that we know when we could potentially remove the fallback?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that'd make sense. |
||
| }), client.WithSessionDialer(func(ctx context.Context, proto string, meta map[string][]string) (net.Conn, error) { | ||
| return d.DockerAPI.DialHijack(ctx, "/session", proto, meta) | ||
| }), | ||
| }, opts...) | ||
| c, err = client.New(ctx, "", opts...) | ||
| if err == nil { | ||
| workers, err = c.ListWorkers(ctx) | ||
| if err != nil { | ||
| c.Close() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return c, workers, err | ||
| } | ||
|
|
||
| type features struct { | ||
|
|
@@ -82,15 +108,15 @@ type features struct { | |
| func (d *Driver) Features(ctx context.Context) map[driver.Feature]bool { | ||
| d.features.once.Do(func() { | ||
| var useContainerdSnapshotter bool | ||
| if c, err := d.Client(ctx); err == nil { | ||
| workers, _ := c.ListWorkers(ctx) | ||
| for _, w := range workers { | ||
| if _, ok := w.Labels["org.mobyproject.buildkit.worker.snapshotter"]; ok { | ||
| useContainerdSnapshotter = true | ||
| } | ||
| } | ||
| c, workers, err := d.client(ctx) | ||
| if err != nil { | ||
| c.Close() | ||
| } | ||
| for _, w := range workers { | ||
| if _, ok := w.Labels["org.mobyproject.buildkit.worker.snapshotter"]; ok { | ||
| useContainerdSnapshotter = true | ||
| } | ||
| } | ||
| d.features.list = map[driver.Feature]bool{ | ||
| driver.OCIExporter: useContainerdSnapshotter, | ||
| driver.DockerExporter: useContainerdSnapshotter, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive by review:
Is this not missing a
returnafterc.Close()? Here the secondif err != nil {can happen afterListWorkersand it does not look like that is the actual intent.