driver: update history api check

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

@ -2,15 +2,14 @@ package driver
import ( import (
"context" "context"
"io"
"github.com/docker/buildx/store" "github.com/docker/buildx/store"
"github.com/docker/buildx/util/progress" "github.com/docker/buildx/util/progress"
clitypes "github.com/docker/cli/cli/config/types" clitypes "github.com/docker/cli/cli/config/types"
controlapi "github.com/moby/buildkit/api/services/control" controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/client" "github.com/moby/buildkit/client"
"github.com/moby/buildkit/util/grpcerrors"
"github.com/pkg/errors" "github.com/pkg/errors"
"google.golang.org/grpc/codes"
) )
var ErrNotRunning = errors.Errorf("driver not running") var ErrNotRunning = errors.Errorf("driver not running")
@ -93,25 +92,21 @@ func Boot(ctx, clientContext context.Context, d Driver, pw progress.Writer) (*cl
} }
} }
func HistoryAPISupported(ctx context.Context, c *client.Client) (res bool) { func HistoryAPISupported(ctx context.Context, c *client.Client) 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{ cl, err := c.ControlClient().ListenBuildHistory(ctx, &controlapi.BuildHistoryRequest{
ActiveOnly: true, ActiveOnly: true,
Ref: "buildx-dummy-ref", // dummy ref to check if the server supports the API Ref: "buildx-test-history-api-feature", // dummy ref to check if the server supports the API
EarlyExit: true, EarlyExit: true,
}) })
if err != nil { if err != nil {
checkErrF(err) return false
return }
for {
_, err := cl.Recv()
if errors.Is(err, io.EOF) {
return true
} else if err != nil {
return false
}
} }
_, err = cl.Recv()
checkErrF(err)
return
} }

Loading…
Cancel
Save