driver: check history capability

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-05-26 10:21:48 +02:00
parent 5e2f8bd64a
commit 9b723ece46
6 changed files with 59 additions and 6 deletions

View File

@ -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
}