mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #14047 from Microsoft/10662-versionadd
Add build time to version and tidy output
This commit is contained in:
commit
5c93c265f6
6 changed files with 37 additions and 27 deletions
|
@ -23,17 +23,21 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
|
||||||
|
|
||||||
cmd.ParseFlags(args, true)
|
cmd.ParseFlags(args, true)
|
||||||
|
|
||||||
|
fmt.Println("Client:")
|
||||||
if dockerversion.VERSION != "" {
|
if dockerversion.VERSION != "" {
|
||||||
fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION)
|
fmt.Fprintf(cli.out, " Version: %s\n", dockerversion.VERSION)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(cli.out, "Client API version: %s\n", api.Version)
|
fmt.Fprintf(cli.out, " API version: %s\n", api.Version)
|
||||||
fmt.Fprintf(cli.out, "Go version (client): %s\n", runtime.Version())
|
fmt.Fprintf(cli.out, " Go version: %s\n", runtime.Version())
|
||||||
if dockerversion.GITCOMMIT != "" {
|
if dockerversion.GITCOMMIT != "" {
|
||||||
fmt.Fprintf(cli.out, "Git commit (client): %s\n", dockerversion.GITCOMMIT)
|
fmt.Fprintf(cli.out, " Git commit: %s\n", dockerversion.GITCOMMIT)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(cli.out, "OS/Arch (client): %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
if dockerversion.BUILDTIME != "" {
|
||||||
|
fmt.Fprintf(cli.out, " Built: %s\n", dockerversion.BUILDTIME)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(cli.out, " OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
||||||
if utils.ExperimentalBuild() {
|
if utils.ExperimentalBuild() {
|
||||||
fmt.Fprintf(cli.out, "Experimental (client): true\n")
|
fmt.Fprintf(cli.out, " Experimental: true\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
stream, _, _, err := cli.call("GET", "/version", nil, nil)
|
stream, _, _, err := cli.call("GET", "/version", nil, nil)
|
||||||
|
@ -47,15 +51,20 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(cli.out, "Server version: %s\n", v.Version)
|
fmt.Println("\nServer:")
|
||||||
|
fmt.Fprintf(cli.out, " Version: %s\n", v.Version)
|
||||||
if v.ApiVersion != "" {
|
if v.ApiVersion != "" {
|
||||||
fmt.Fprintf(cli.out, "Server API version: %s\n", v.ApiVersion)
|
fmt.Fprintf(cli.out, " API version: %s\n", v.ApiVersion)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(cli.out, "Go version (server): %s\n", v.GoVersion)
|
fmt.Fprintf(cli.out, " Go version: %s\n", v.GoVersion)
|
||||||
fmt.Fprintf(cli.out, "Git commit (server): %s\n", v.GitCommit)
|
fmt.Fprintf(cli.out, " Git commit: %s\n", v.GitCommit)
|
||||||
fmt.Fprintf(cli.out, "OS/Arch (server): %s/%s\n", v.Os, v.Arch)
|
if len(v.BuildTime) > 0 {
|
||||||
|
fmt.Fprintf(cli.out, " Built: %s\n", v.BuildTime)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(cli.out, " OS/Arch: %s/%s\n", v.Os, v.Arch)
|
||||||
if v.Experimental {
|
if v.Experimental {
|
||||||
fmt.Fprintf(cli.out, "Experimental (server): true\n")
|
fmt.Fprintf(cli.out, " Experimental: true\n")
|
||||||
}
|
}
|
||||||
|
fmt.Fprintf(cli.out, "\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,6 +249,7 @@ func (s *Server) getVersion(version version.Version, w http.ResponseWriter, r *h
|
||||||
GoVersion: runtime.Version(),
|
GoVersion: runtime.Version(),
|
||||||
Os: runtime.GOOS,
|
Os: runtime.GOOS,
|
||||||
Arch: runtime.GOARCH,
|
Arch: runtime.GOARCH,
|
||||||
|
BuildTime: dockerversion.BUILDTIME,
|
||||||
}
|
}
|
||||||
|
|
||||||
if version.GreaterThanOrEqualTo("1.19") {
|
if version.GreaterThanOrEqualTo("1.19") {
|
||||||
|
|
|
@ -142,6 +142,7 @@ type Version struct {
|
||||||
Arch string
|
Arch string
|
||||||
KernelVersion string `json:",omitempty"`
|
KernelVersion string `json:",omitempty"`
|
||||||
Experimental bool `json:",omitempty"`
|
Experimental bool `json:",omitempty"`
|
||||||
|
BuildTime string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET "/info"
|
// GET "/info"
|
||||||
|
|
|
@ -71,6 +71,7 @@ if command -v git &> /dev/null && git rev-parse &> /dev/null; then
|
||||||
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
|
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
|
||||||
GITCOMMIT="$GITCOMMIT-dirty"
|
GITCOMMIT="$GITCOMMIT-dirty"
|
||||||
fi
|
fi
|
||||||
|
BUILDTIME=$(date -u)
|
||||||
elif [ "$DOCKER_GITCOMMIT" ]; then
|
elif [ "$DOCKER_GITCOMMIT" ]; then
|
||||||
GITCOMMIT="$DOCKER_GITCOMMIT"
|
GITCOMMIT="$DOCKER_GITCOMMIT"
|
||||||
else
|
else
|
||||||
|
|
|
@ -10,6 +10,7 @@ package dockerversion
|
||||||
var (
|
var (
|
||||||
GITCOMMIT string = "$GITCOMMIT"
|
GITCOMMIT string = "$GITCOMMIT"
|
||||||
VERSION string = "$VERSION"
|
VERSION string = "$VERSION"
|
||||||
|
BUILDTIME string = "$BUILDTIME"
|
||||||
|
|
||||||
IAMSTATIC string = "${IAMSTATIC:-true}"
|
IAMSTATIC string = "${IAMSTATIC:-true}"
|
||||||
INITSHA1 string = "$DOCKER_INITSHA1"
|
INITSHA1 string = "$DOCKER_INITSHA1"
|
||||||
|
|
|
@ -15,23 +15,20 @@ func (s *DockerSuite) TestVersionEnsureSucceeds(c *check.C) {
|
||||||
c.Fatalf("failed to execute docker version: %s, %v", out, err)
|
c.Fatalf("failed to execute docker version: %s, %v", out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stringsToCheck := []string{
|
stringsToCheck := map[string]int{
|
||||||
"Client version:",
|
"Client:": 1,
|
||||||
"Client API version:",
|
"Server:": 1,
|
||||||
"Go version (client):",
|
" Version:": 2,
|
||||||
"Git commit (client):",
|
" API version:": 2,
|
||||||
"OS/Arch (client):",
|
" Go version:": 2,
|
||||||
"Server version:",
|
" Git commit:": 2,
|
||||||
"Server API version:",
|
" OS/Arch:": 2,
|
||||||
"Go version (server):",
|
" Built:": 2,
|
||||||
"Git commit (server):",
|
|
||||||
"OS/Arch (server):",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, linePrefix := range stringsToCheck {
|
for k, v := range stringsToCheck {
|
||||||
if !strings.Contains(out, linePrefix) {
|
if strings.Count(out, k) != v {
|
||||||
c.Errorf("couldn't find string %v in output", linePrefix)
|
c.Errorf("%v expected %d instances found %d", k, v, strings.Count(out, k))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue