mirror of https://github.com/docker/cli.git
Merge pull request #736 from tiborvass/platform-version
Add platform and its components to docker version output
This commit is contained in:
commit
ace5417954
|
@ -1,34 +1,52 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sort"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/templates"
|
"github.com/docker/cli/templates"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
var versionTemplate = `Client:
|
var versionTemplate = `{{with .Client -}}
|
||||||
Version: {{.Client.Version}}
|
Client:{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}}
|
||||||
API version: {{.Client.APIVersion}}{{if ne .Client.APIVersion .Client.DefaultAPIVersion}} (downgraded from {{.Client.DefaultAPIVersion}}){{end}}
|
Version: {{.Version}}
|
||||||
Go version: {{.Client.GoVersion}}
|
API version: {{.APIVersion}}{{if ne .APIVersion .DefaultAPIVersion}} (downgraded from {{.DefaultAPIVersion}}){{end}}
|
||||||
Git commit: {{.Client.GitCommit}}
|
Go version: {{.GoVersion}}
|
||||||
Built: {{.Client.BuildTime}}
|
Git commit: {{.GitCommit}}
|
||||||
OS/Arch: {{.Client.Os}}/{{.Client.Arch}}{{if .ServerOK}}
|
Built: {{.BuildTime}}
|
||||||
|
OS/Arch: {{.Os}}/{{.Arch}}
|
||||||
|
{{- end}}
|
||||||
|
|
||||||
Server:
|
{{- if .ServerOK}}{{with .Server}}
|
||||||
Version: {{.Server.Version}}
|
|
||||||
API version: {{.Server.APIVersion}} (minimum version {{.Server.MinAPIVersion}})
|
Server:{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}}
|
||||||
Go version: {{.Server.GoVersion}}
|
{{- range $component := .Components}}
|
||||||
Git commit: {{.Server.GitCommit}}
|
{{$component.Name}}:
|
||||||
Built: {{.Server.BuildTime}}
|
{{- if eq $component.Name "Engine" }}
|
||||||
OS/Arch: {{.Server.Os}}/{{.Server.Arch}}
|
Version: {{.Version}}
|
||||||
Experimental: {{.Server.Experimental}}{{end}}`
|
API version: {{index .Details "ApiVersion"}} (minimum version {{index .Details "MinAPIVersion"}})
|
||||||
|
Go version: {{index .Details "GoVersion"}}
|
||||||
|
Git commit: {{index .Details "GitCommit"}}
|
||||||
|
Built: {{index .Details "BuildTime"}}
|
||||||
|
OS/Arch: {{index .Details "Os"}}/{{index .Details "Arch"}}
|
||||||
|
Experimental: {{index .Details "Experimental"}}
|
||||||
|
{{- else }}
|
||||||
|
Version: {{$component.Version}}
|
||||||
|
{{- $detailsOrder := getDetailsOrder $component}}
|
||||||
|
{{- range $key := $detailsOrder}}
|
||||||
|
{{$key}}: {{index $component.Details $key}}
|
||||||
|
{{- end}}
|
||||||
|
{{- end}}
|
||||||
|
{{- end}}
|
||||||
|
{{- end}}{{end}}`
|
||||||
|
|
||||||
type versionOptions struct {
|
type versionOptions struct {
|
||||||
format string
|
format string
|
||||||
|
@ -41,6 +59,8 @@ type versionInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type clientVersion struct {
|
type clientVersion struct {
|
||||||
|
Platform struct{ Name string } `json:",omitempty"`
|
||||||
|
|
||||||
Version string
|
Version string
|
||||||
APIVersion string `json:"ApiVersion"`
|
APIVersion string `json:"ApiVersion"`
|
||||||
DefaultAPIVersion string `json:"DefaultAPIVersion,omitempty"`
|
DefaultAPIVersion string `json:"DefaultAPIVersion,omitempty"`
|
||||||
|
@ -77,15 +97,27 @@ func NewVersionCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reformatDate(buildTime string) string {
|
||||||
|
t, errTime := time.Parse(time.RFC3339Nano, buildTime)
|
||||||
|
if errTime == nil {
|
||||||
|
return t.Format(time.ANSIC)
|
||||||
|
}
|
||||||
|
return buildTime
|
||||||
|
}
|
||||||
|
|
||||||
func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error {
|
func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
templateFormat := versionTemplate
|
templateFormat := versionTemplate
|
||||||
|
tmpl := templates.New("version")
|
||||||
if opts.format != "" {
|
if opts.format != "" {
|
||||||
templateFormat = opts.format
|
templateFormat = opts.format
|
||||||
|
} else {
|
||||||
|
tmpl = tmpl.Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder})
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl, err := templates.Parse(templateFormat)
|
var err error
|
||||||
|
tmpl, err = tmpl.Parse(templateFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.StatusError{StatusCode: 64,
|
return cli.StatusError{StatusCode: 64,
|
||||||
Status: "Template parsing error: " + err.Error()}
|
Status: "Template parsing error: " + err.Error()}
|
||||||
|
@ -103,22 +135,41 @@ func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error {
|
||||||
Arch: runtime.GOARCH,
|
Arch: runtime.GOARCH,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
vd.Client.Platform.Name = cli.PlatformName
|
||||||
serverVersion, err := dockerCli.Client().ServerVersion(ctx)
|
|
||||||
if err == nil {
|
|
||||||
vd.Server = &serverVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
// first we need to make BuildTime more human friendly
|
// first we need to make BuildTime more human friendly
|
||||||
t, errTime := time.Parse(time.RFC3339Nano, vd.Client.BuildTime)
|
vd.Client.BuildTime = reformatDate(vd.Client.BuildTime)
|
||||||
if errTime == nil {
|
|
||||||
vd.Client.BuildTime = t.Format(time.ANSIC)
|
sv, err := dockerCli.Client().ServerVersion(ctx)
|
||||||
|
if err == nil {
|
||||||
|
vd.Server = &sv
|
||||||
|
foundEngine := false
|
||||||
|
for _, component := range sv.Components {
|
||||||
|
if component.Name == "Engine" {
|
||||||
|
foundEngine = true
|
||||||
|
buildTime, ok := component.Details["BuildTime"]
|
||||||
|
if ok {
|
||||||
|
component.Details["BuildTime"] = reformatDate(buildTime)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if vd.ServerOK() {
|
if !foundEngine {
|
||||||
t, errTime = time.Parse(time.RFC3339Nano, vd.Server.BuildTime)
|
vd.Server.Components = append(vd.Server.Components, types.ComponentVersion{
|
||||||
if errTime == nil {
|
Name: "Engine",
|
||||||
vd.Server.BuildTime = t.Format(time.ANSIC)
|
Version: sv.Version,
|
||||||
|
Details: map[string]string{
|
||||||
|
"ApiVersion": sv.APIVersion,
|
||||||
|
"MinAPIVersion": sv.MinAPIVersion,
|
||||||
|
"GitCommit": sv.GitCommit,
|
||||||
|
"GoVersion": sv.GoVersion,
|
||||||
|
"Os": sv.Os,
|
||||||
|
"Arch": sv.Arch,
|
||||||
|
"BuildTime": reformatDate(vd.Server.BuildTime),
|
||||||
|
"Experimental": fmt.Sprintf("%t", sv.Experimental),
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,3 +179,12 @@ func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error {
|
||||||
dockerCli.Out().Write([]byte{'\n'})
|
dockerCli.Out().Write([]byte{'\n'})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDetailsOrder(v types.ComponentVersion) []string {
|
||||||
|
out := make([]string, 0, len(v.Details))
|
||||||
|
for k := range v.Details {
|
||||||
|
out = append(out, k)
|
||||||
|
}
|
||||||
|
sort.Strings(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cli
|
||||||
// Default build-time variable.
|
// Default build-time variable.
|
||||||
// These values are overriding via ldflags
|
// These values are overriding via ldflags
|
||||||
var (
|
var (
|
||||||
|
PlatformName = ""
|
||||||
Version = "unknown-version"
|
Version = "unknown-version"
|
||||||
GitCommit = "unknown-commit"
|
GitCommit = "unknown-commit"
|
||||||
BuildTime = "unknown-buildtime"
|
BuildTime = "unknown-buildtime"
|
||||||
|
|
|
@ -10,7 +10,7 @@ CROSS_IMAGE_NAME = docker-cli-cross$(IMAGE_TAG)
|
||||||
VALIDATE_IMAGE_NAME = docker-cli-shell-validate$(IMAGE_TAG)
|
VALIDATE_IMAGE_NAME = docker-cli-shell-validate$(IMAGE_TAG)
|
||||||
MOUNTS = -v "$(CURDIR)":/go/src/github.com/docker/cli
|
MOUNTS = -v "$(CURDIR)":/go/src/github.com/docker/cli
|
||||||
VERSION = $(shell cat VERSION)
|
VERSION = $(shell cat VERSION)
|
||||||
ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT
|
ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM
|
||||||
|
|
||||||
# build docker image (dockerfiles/Dockerfile.build)
|
# build docker image (dockerfiles/Dockerfile.build)
|
||||||
.PHONY: build_docker_image
|
.PHONY: build_docker_image
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
PLATFORM=${PLATFORM:-}
|
||||||
VERSION=${VERSION:-"unknown-version"}
|
VERSION=${VERSION:-"unknown-version"}
|
||||||
GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)}
|
GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)}
|
||||||
BUILDTIME=${BUILDTIME:-$(date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')}
|
BUILDTIME=${BUILDTIME:-$(date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')}
|
||||||
|
|
||||||
|
PLATFORM_LDFLAGS=
|
||||||
|
if test -n "${PLATFORM}"; then
|
||||||
|
PLATFORM_LDFLAGS="-X \"github.com/docker/cli/cli.PlatformName=${PLATFORM}\""
|
||||||
|
fi
|
||||||
|
|
||||||
export LDFLAGS="\
|
export LDFLAGS="\
|
||||||
-w \
|
-w \
|
||||||
-X github.com/docker/cli/cli.GitCommit=${GITCOMMIT} \
|
${PLATFORM_LDFLAGS} \
|
||||||
-X github.com/docker/cli/cli.BuildTime=${BUILDTIME} \
|
-X \"github.com/docker/cli/cli.GitCommit=${GITCOMMIT}\" \
|
||||||
-X github.com/docker/cli/cli.Version=${VERSION} \
|
-X \"github.com/docker/cli/cli.BuildTime=${BUILDTIME}\" \
|
||||||
|
-X \"github.com/docker/cli/cli.Version=${VERSION}\" \
|
||||||
${LDFLAGS:-} \
|
${LDFLAGS:-} \
|
||||||
"
|
"
|
||||||
|
|
||||||
|
|
|
@ -55,10 +55,16 @@ func Parse(format string) (*template.Template, error) {
|
||||||
return NewParse("", format)
|
return NewParse("", format)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates a new empty template with the provided tag and built-in
|
||||||
|
// template functions.
|
||||||
|
func New(tag string) *template.Template {
|
||||||
|
return template.New(tag).Funcs(basicFunctions)
|
||||||
|
}
|
||||||
|
|
||||||
// NewParse creates a new tagged template with the basic functions
|
// NewParse creates a new tagged template with the basic functions
|
||||||
// and parses the given format.
|
// and parses the given format.
|
||||||
func NewParse(tag, format string) (*template.Template, error) {
|
func NewParse(tag, format string) (*template.Template, error) {
|
||||||
return template.New(tag).Funcs(basicFunctions).Parse(format)
|
return New(tag).Parse(format)
|
||||||
}
|
}
|
||||||
|
|
||||||
// padWithSpace adds whitespace to the input if the input is non-empty
|
// padWithSpace adds whitespace to the input if the input is non-empty
|
||||||
|
|
|
@ -5,7 +5,7 @@ github.com/coreos/etcd v3.2.1
|
||||||
github.com/cpuguy83/go-md2man a65d4d2de4d5f7c74868dfa9b202a3c8be315aaa
|
github.com/cpuguy83/go-md2man a65d4d2de4d5f7c74868dfa9b202a3c8be315aaa
|
||||||
github.com/davecgh/go-spew 346938d642f2ec3594ed81d874461961cd0faa76
|
github.com/davecgh/go-spew 346938d642f2ec3594ed81d874461961cd0faa76
|
||||||
github.com/docker/distribution edc3ab29cdff8694dd6feb85cfeb4b5f1b38ed9c
|
github.com/docker/distribution edc3ab29cdff8694dd6feb85cfeb4b5f1b38ed9c
|
||||||
github.com/docker/docker 5e5fadb3c0201553929d4a6ea8dc8f9d8a1e56fe
|
github.com/docker/docker a1be987ea9e03e5ebdb1b415a7acdd8d6f0aaa08
|
||||||
github.com/docker/docker-credential-helpers 3c90bd29a46b943b2a9842987b58fb91a7c1819b
|
github.com/docker/docker-credential-helpers 3c90bd29a46b943b2a9842987b58fb91a7c1819b
|
||||||
|
|
||||||
# the docker/go package contains a customized version of canonical/json
|
# the docker/go package contains a customized version of canonical/json
|
||||||
|
|
|
@ -107,9 +107,21 @@ type Ping struct {
|
||||||
Experimental bool
|
Experimental bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ComponentVersion describes the version information for a specific component.
|
||||||
|
type ComponentVersion struct {
|
||||||
|
Name string
|
||||||
|
Version string
|
||||||
|
Details map[string]string `json:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Version contains response of Engine API:
|
// Version contains response of Engine API:
|
||||||
// GET "/version"
|
// GET "/version"
|
||||||
type Version struct {
|
type Version struct {
|
||||||
|
Platform struct{ Name string } `json:",omitempty"`
|
||||||
|
Components []ComponentVersion `json:",omitempty"`
|
||||||
|
|
||||||
|
// The following fields are deprecated, they relate to the Engine component and are kept for backwards compatibility
|
||||||
|
|
||||||
Version string
|
Version string
|
||||||
APIVersion string `json:"ApiVersion"`
|
APIVersion string `json:"ApiVersion"`
|
||||||
MinAPIVersion string `json:"MinAPIVersion,omitempty"`
|
MinAPIVersion string `json:"MinAPIVersion,omitempty"`
|
||||||
|
|
|
@ -30,7 +30,7 @@ github.com/moby/buildkit aaff9d591ef128560018433fe61beb802e149de8
|
||||||
github.com/tonistiigi/fsutil dea3a0da73aee887fc02142d995be764106ac5e2
|
github.com/tonistiigi/fsutil dea3a0da73aee887fc02142d995be764106ac5e2
|
||||||
|
|
||||||
#get libnetwork packages
|
#get libnetwork packages
|
||||||
github.com/docker/libnetwork 64ae58878fc8f95e4a167499d654e13fa36abdc7
|
github.com/docker/libnetwork 9bca9a4a220b158cc94402e0f8c2c7714eb6f503
|
||||||
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
|
github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9
|
||||||
github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
|
github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
|
||||||
github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
|
github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
|
||||||
|
@ -42,7 +42,7 @@ github.com/hashicorp/go-multierror fcdddc395df1ddf4247c69bd436e84cfa0733f7e
|
||||||
github.com/hashicorp/serf 598c54895cc5a7b1a24a398d635e8c0ea0959870
|
github.com/hashicorp/serf 598c54895cc5a7b1a24a398d635e8c0ea0959870
|
||||||
github.com/docker/libkv 1d8431073ae03cdaedb198a89722f3aab6d418ef
|
github.com/docker/libkv 1d8431073ae03cdaedb198a89722f3aab6d418ef
|
||||||
github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25
|
github.com/vishvananda/netns 604eaf189ee867d8c147fafc28def2394e878d25
|
||||||
github.com/vishvananda/netlink bd6d5de5ccef2d66b0a26177928d0d8895d7f969
|
github.com/vishvananda/netlink b2de5d10e38ecce8607e6b438b6d174f389a004e
|
||||||
github.com/BurntSushi/toml f706d00e3de6abe700c994cdd545a1a4915af060
|
github.com/BurntSushi/toml f706d00e3de6abe700c994cdd545a1a4915af060
|
||||||
github.com/samuel/go-zookeeper d0e0d8e11f318e000a8cc434616d69e329edc374
|
github.com/samuel/go-zookeeper d0e0d8e11f318e000a8cc434616d69e329edc374
|
||||||
github.com/deckarep/golang-set ef32fa3046d9f249d399f98ebaf9be944430fd1d
|
github.com/deckarep/golang-set ef32fa3046d9f249d399f98ebaf9be944430fd1d
|
||||||
|
|
Loading…
Reference in New Issue