diff --git a/commands/util.go b/commands/util.go index f2339a7a..a75d3420 100644 --- a/commands/util.go +++ b/commands/util.go @@ -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 diff --git a/driver/docker-container/driver.go b/driver/docker-container/driver.go index 86b35b3f..ac99d61a 100644 --- a/driver/docker-container/driver.go +++ b/driver/docker-container/driver.go @@ -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 { diff --git a/driver/docker/driver.go b/driver/docker/driver.go index 26b6198b..d3d05d48 100644 --- a/driver/docker/driver.go +++ b/driver/docker/driver.go @@ -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 } diff --git a/driver/driver.go b/driver/driver.go index 1eceb5aa..ed108031 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -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) diff --git a/driver/kubernetes/driver.go b/driver/kubernetes/driver.go index 92725dff..7fae8170 100644 --- a/driver/kubernetes/driver.go +++ b/driver/kubernetes/driver.go @@ -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 diff --git a/driver/remote/driver.go b/driver/remote/driver.go index ed52bea0..df2bbcdb 100644 --- a/driver/remote/driver.go +++ b/driver/remote/driver.go @@ -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 }