ls: adds fallback if buildkit version info unimplemented

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-05-09 16:17:01 +02:00
parent 6e3babc461
commit 57156ee95c
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
6 changed files with 38 additions and 3 deletions

View File

@ -314,9 +314,10 @@ func loadInfoData(ctx context.Context, d *dinfo) error {
inf, err := c.Info(ctx)
if err != nil {
if st, ok := grpcerrors.AsGRPCStatus(err); ok && st.Code() == codes.Unimplemented {
d.version = "N/A"
} else {
return errors.Wrap(err, "getting info")
d.version, err = d.di.Driver.Version(ctx)
if err != nil {
return errors.Wrap(err, "getting version")
}
}
} else {
d.version = inf.BuildkitVersion.Version

View File

@ -8,6 +8,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"time"
"github.com/docker/buildx/driver"
@ -286,6 +287,22 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) {
}, nil
}
func (d *Driver) Version(ctx context.Context) (string, error) {
bufStdout := &bytes.Buffer{}
bufStderr := &bytes.Buffer{}
if err := d.run(ctx, []string{"buildkitd", "--version"}, bufStdout, bufStderr); err != nil {
if bufStderr.Len() > 0 {
return "", errors.Wrap(err, bufStderr.String())
}
return "", err
}
version := strings.Fields(bufStdout.String())
if len(version) != 4 {
return "", errors.Errorf("unexpected version format: %s", bufStdout.String())
}
return version[2], nil
}
func (d *Driver) Stop(ctx context.Context, force bool) error {
info, err := d.Info(ctx)
if err != nil {

View File

@ -29,6 +29,14 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) {
}, nil
}
func (d *Driver) Version(ctx context.Context) (string, error) {
v, err := d.DockerAPI.ServerVersion(ctx)
if err != nil {
return "", errors.Wrapf(driver.ErrNotConnecting, err.Error())
}
return v.Version, nil
}
func (d *Driver) Stop(ctx context.Context, force bool) error {
return nil
}

View File

@ -53,6 +53,7 @@ type Driver interface {
Factory() Factory
Bootstrap(context.Context, progress.Logger) error
Info(context.Context) (*Info, error)
Version(context.Context) (string, error)
Stop(ctx context.Context, force bool) error
Rm(ctx context.Context, force, rmVolume, rmDaemon bool) error
Client(ctx context.Context) (*client.Client, error)

View File

@ -160,6 +160,10 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) {
}, nil
}
func (d *Driver) Version(ctx context.Context) (string, error) {
return "", nil
}
func (d *Driver) Stop(ctx context.Context, force bool) error {
// future version may scale the replicas to zero here
return nil

View File

@ -41,6 +41,10 @@ func (d *Driver) Info(ctx context.Context) (*driver.Info, error) {
}, nil
}
func (d *Driver) Version(ctx context.Context) (string, error) {
return "", nil
}
func (d *Driver) Stop(ctx context.Context, force bool) error {
return nil
}