mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
driver: update history api check
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
e7034f66bc
commit
f8fa526678
@ -2,15 +2,14 @@ package driver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"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")
|
||||
@ -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) {
|
||||
res = true
|
||||
checkErrF := func(err error) {
|
||||
if s, ok := grpcerrors.AsGRPCStatus(err); ok {
|
||||
if s.Code() == codes.Unimplemented {
|
||||
res = false
|
||||
}
|
||||
}
|
||||
}
|
||||
func HistoryAPISupported(ctx context.Context, c *client.Client) bool {
|
||||
cl, err := c.ControlClient().ListenBuildHistory(ctx, &controlapi.BuildHistoryRequest{
|
||||
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,
|
||||
})
|
||||
if err != nil {
|
||||
checkErrF(err)
|
||||
return
|
||||
return false
|
||||
}
|
||||
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…
x
Reference in New Issue
Block a user