Skip to content

Commit

Permalink
Merge pull request #1856 from crazy-max/history-feature-update
Browse files Browse the repository at this point in the history
driver: update history api check
  • Loading branch information
crazy-max authored May 31, 2023
2 parents 4abff3c + f8fa526 commit 0758a9b
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}

0 comments on commit 0758a9b

Please sign in to comment.