mirror of https://github.com/docker/cli.git
Merge pull request #31022 from jmzwcn/issue30994
docker version output is not consistent when there are downgrades or incompatibilities #30994
This commit is contained in:
commit
e959064068
|
@ -1,7 +1,6 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -17,7 +16,7 @@ import (
|
||||||
|
|
||||||
var versionTemplate = `Client:
|
var versionTemplate = `Client:
|
||||||
Version: {{.Client.Version}}
|
Version: {{.Client.Version}}
|
||||||
API version: {{.Client.APIVersion}}
|
API version: {{.Client.APIVersion}}{{if ne .Client.APIVersion .Client.DefaultAPIVersion}} (downgraded from {{.Client.DefaultAPIVersion}}){{end}}
|
||||||
Go version: {{.Client.GoVersion}}
|
Go version: {{.Client.GoVersion}}
|
||||||
Git commit: {{.Client.GitCommit}}
|
Git commit: {{.Client.GitCommit}}
|
||||||
Built: {{.Client.BuildTime}}
|
Built: {{.Client.BuildTime}}
|
||||||
|
@ -36,6 +35,29 @@ type versionOptions struct {
|
||||||
format string
|
format string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// versionInfo contains version information of both the Client, and Server
|
||||||
|
type versionInfo struct {
|
||||||
|
Client clientVersion
|
||||||
|
Server *types.Version
|
||||||
|
}
|
||||||
|
|
||||||
|
type clientVersion struct {
|
||||||
|
Version string
|
||||||
|
APIVersion string `json:"ApiVersion"`
|
||||||
|
DefaultAPIVersion string `json:"DefaultAPIVersion,omitempty"`
|
||||||
|
GitCommit string
|
||||||
|
GoVersion string
|
||||||
|
Os string
|
||||||
|
Arch string
|
||||||
|
BuildTime string `json:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServerOK returns true when the client could connect to the docker server
|
||||||
|
// and parse the information received. It returns false otherwise.
|
||||||
|
func (v versionInfo) ServerOK() bool {
|
||||||
|
return v.Server != nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewVersionCommand creates a new cobra.Command for `docker version`
|
// NewVersionCommand creates a new cobra.Command for `docker version`
|
||||||
func NewVersionCommand(dockerCli *command.DockerCli) *cobra.Command {
|
func NewVersionCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
var opts versionOptions
|
var opts versionOptions
|
||||||
|
@ -70,20 +92,16 @@ func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error {
|
||||||
Status: "Template parsing error: " + err.Error()}
|
Status: "Template parsing error: " + err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
APIVersion := dockerCli.Client().ClientVersion()
|
vd := versionInfo{
|
||||||
if defaultAPIVersion := dockerCli.DefaultVersion(); APIVersion != defaultAPIVersion {
|
Client: clientVersion{
|
||||||
APIVersion = fmt.Sprintf("%s (downgraded from %s)", APIVersion, defaultAPIVersion)
|
Version: dockerversion.Version,
|
||||||
}
|
APIVersion: dockerCli.Client().ClientVersion(),
|
||||||
|
DefaultAPIVersion: dockerCli.DefaultVersion(),
|
||||||
vd := types.VersionResponse{
|
GoVersion: runtime.Version(),
|
||||||
Client: &types.Version{
|
GitCommit: dockerversion.GitCommit,
|
||||||
Version: dockerversion.Version,
|
BuildTime: dockerversion.BuildTime,
|
||||||
APIVersion: APIVersion,
|
Os: runtime.GOOS,
|
||||||
GoVersion: runtime.Version(),
|
Arch: runtime.GOARCH,
|
||||||
GitCommit: dockerversion.GitCommit,
|
|
||||||
BuildTime: dockerversion.BuildTime,
|
|
||||||
Os: runtime.GOOS,
|
|
||||||
Arch: runtime.GOARCH,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue