driver: check history capability

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
pull/1846/head
CrazyMax 2 years ago
parent 5e2f8bd64a
commit 9b723ece46
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7

@ -388,12 +388,19 @@ func (d *Driver) Factory() driver.Factory {
}
func (d *Driver) Features() map[driver.Feature]bool {
var historyAPI bool
ctx := context.Background()
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: true,
driver.CacheExport: true,
driver.MultiPlatform: true,
driver.CacheExport: true,
driver.MultiPlatform: true,
driver.HistoryAPI: historyAPI,
}
}

@ -60,6 +60,7 @@ func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
func (d *Driver) Features() map[driver.Feature]bool {
var useContainerdSnapshotter bool
var historyAPI bool
ctx := context.Background()
c, err := d.Client(ctx)
if err == nil {
@ -69,6 +70,7 @@ func (d *Driver) Features() map[driver.Feature]bool {
useContainerdSnapshotter = true
}
}
historyAPI = driver.HistoryAPISupported(ctx, c)
c.Close()
}
return map[driver.Feature]bool{
@ -76,6 +78,7 @@ func (d *Driver) Features() map[driver.Feature]bool {
driver.DockerExporter: useContainerdSnapshotter,
driver.CacheExport: useContainerdSnapshotter,
driver.MultiPlatform: useContainerdSnapshotter,
driver.HistoryAPI: historyAPI,
}
}

@ -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")
@ -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 {
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
EarlyExit: true,
})
if err != nil {
checkErrF(err)
return
}
_, err = cl.Recv()
checkErrF(err)
return
}

@ -7,3 +7,5 @@ const DockerExporter Feature = "Docker exporter"
const CacheExport Feature = "cache export"
const MultiPlatform Feature = "multiple platforms"
const HistoryAPI Feature = "history api"

@ -229,11 +229,18 @@ func (d *Driver) Factory() driver.Factory {
}
func (d *Driver) Features() map[driver.Feature]bool {
var historyAPI bool
ctx := context.Background()
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)
driver.HistoryAPI: historyAPI,
}
}

@ -88,11 +88,19 @@ func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
}
func (d *Driver) Features() map[driver.Feature]bool {
var historyAPI bool
ctx := context.Background()
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: true,
driver.CacheExport: true,
driver.MultiPlatform: true,
driver.HistoryAPI: historyAPI,
}
}

Loading…
Cancel
Save