mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-29 17:05:46 +08:00
Merge pull request #1856 from crazy-max/history-feature-update
driver: update history api check
This commit is contained in:
commit
0758a9b75d
@ -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…
x
Reference in New Issue
Block a user