mirror of
https://github.com/docker/buildx.git
synced 2024-11-22 15:37:16 +08:00
ls: adds fallback if buildkit version info unimplemented
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
6e3babc461
commit
57156ee95c
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user