-
Notifications
You must be signed in to change notification settings - Fork 617
driver: check history capability #1846
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
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,8 +6,11 @@ import ( | |
| "github.com/docker/buildx/store" | ||
| "github.com/docker/buildx/util/progress" | ||
| clitypes "github.com/docker/cli/cli/config/types" | ||
| controlapi "github.com/moby/buildkit/api/services/control" | ||
| "github.com/moby/buildkit/client" | ||
| "github.com/moby/buildkit/util/grpcerrors" | ||
| "github.com/pkg/errors" | ||
| "google.golang.org/grpc/codes" | ||
| ) | ||
|
|
||
| var ErrNotRunning = errors.Errorf("driver not running") | ||
|
|
@@ -57,7 +60,7 @@ type Driver interface { | |
| Stop(ctx context.Context, force bool) error | ||
| Rm(ctx context.Context, force, rmVolume, rmDaemon bool) error | ||
| Client(ctx context.Context) (*client.Client, error) | ||
| Features() map[Feature]bool | ||
| Features(ctx context.Context) map[Feature]bool | ||
| IsMobyDriver() bool | ||
| Config() InitConfig | ||
| } | ||
|
|
@@ -89,3 +92,26 @@ func Boot(ctx, clientContext context.Context, d Driver, pw progress.Writer) (*cl | |
| return c, nil | ||
| } | ||
| } | ||
|
|
||
| func HistoryAPISupported(ctx context.Context, c *client.Client) (res bool) { | ||
| res = true | ||
| checkErrF := func(err error) { | ||
| if s, ok := grpcerrors.AsGRPCStatus(err); ok { | ||
| if s.Code() == codes.Unimplemented { | ||
|
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. What error except for EOF in here means there is support? |
||
| res = false | ||
| } | ||
| } | ||
| } | ||
| cl, err := c.ControlClient().ListenBuildHistory(ctx, &controlapi.BuildHistoryRequest{ | ||
| ActiveOnly: true, | ||
| Ref: "buildx-dummy-ref", // dummy ref to check if the server supports the API | ||
|
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. "buildx-test-history-api-feature" so that if you look at it from server side you understand where the request is coming from. |
||
| EarlyExit: true, | ||
| }) | ||
| if err != nil { | ||
| checkErrF(err) | ||
| return | ||
| } | ||
| _, err = cl.Recv() | ||
|
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. Client should be read until it is empty. It can be closed/canceled if there is an issue. |
||
| checkErrF(err) | ||
| return | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,12 +228,18 @@ func (d *Driver) Factory() driver.Factory { | |
| return d.factory | ||
| } | ||
|
|
||
| func (d *Driver) Features() map[driver.Feature]bool { | ||
| func (d *Driver) Features(ctx context.Context) map[driver.Feature]bool { | ||
| var historyAPI bool | ||
| c, err := d.Client(ctx) | ||
| if err == nil { | ||
| historyAPI = driver.HistoryAPISupported(ctx, c) | ||
| c.Close() | ||
| } | ||
| return map[driver.Feature]bool{ | ||
| driver.OCIExporter: true, | ||
| driver.DockerExporter: d.DockerAPI != nil, | ||
|
|
||
| driver.CacheExport: true, | ||
| driver.MultiPlatform: true, // Untested (needs multiple Driver instances) | ||
| driver.CacheExport: true, | ||
| driver.MultiPlatform: true, // Untested (needs multiple Driver instances) | ||
|
Collaborator
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. Unrelated, but I think this comment is out-of-date now? I think this is tested now, at least we have docs for this scenario?
Member
Author
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. |
||
| driver.HistoryAPI: historyAPI, | ||
| } | ||
| } | ||
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.
This call is expensive. It makes an new
docker exec.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.
The client is cached
buildx/driver/manager.go
Lines 157 to 162 in a906149
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.
That is not the struct that's get called in the line 392.