From 87eae0d659d6e4bb75942455f3f73a74f54ed3b9 Mon Sep 17 00:00:00 2001 From: John Howard Date: Fri, 19 Jun 2015 10:03:13 -0700 Subject: [PATCH] Add branch and build time to version Signed-off-by: John Howard --- api/client/version.go | 33 ++++++++++++++-------- api/server/server.go | 1 + api/types/types.go | 1 + hack/make.sh | 1 + hack/make/.go-autogen | 1 + integration-cli/docker_cli_version_test.go | 27 ++++++++---------- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/api/client/version.go b/api/client/version.go index 85991dc9a5..33c54c5ffe 100644 --- a/api/client/version.go +++ b/api/client/version.go @@ -23,17 +23,21 @@ func (cli *DockerCli) CmdVersion(args ...string) error { cmd.ParseFlags(args, true) + fmt.Println("Client:") 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, "Go version (client): %s\n", runtime.Version()) + fmt.Fprintf(cli.out, " API version: %s\n", api.Version) + fmt.Fprintf(cli.out, " Go version: %s\n", runtime.Version()) 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() { - fmt.Fprintf(cli.out, "Experimental (client): true\n") + fmt.Fprintf(cli.out, " Experimental: true\n") } stream, _, _, err := cli.call("GET", "/version", nil, nil) @@ -47,15 +51,20 @@ func (cli *DockerCli) CmdVersion(args ...string) error { 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 != "" { - 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, "Git commit (server): %s\n", v.GitCommit) - fmt.Fprintf(cli.out, "OS/Arch (server): %s/%s\n", v.Os, v.Arch) + fmt.Fprintf(cli.out, " Go version: %s\n", v.GoVersion) + fmt.Fprintf(cli.out, " Git commit: %s\n", v.GitCommit) + 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 { - fmt.Fprintf(cli.out, "Experimental (server): true\n") + fmt.Fprintf(cli.out, " Experimental: true\n") } + fmt.Fprintf(cli.out, "\n") return nil } diff --git a/api/server/server.go b/api/server/server.go index 6e6631fc41..f9a6be3907 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -249,6 +249,7 @@ func (s *Server) getVersion(version version.Version, w http.ResponseWriter, r *h GoVersion: runtime.Version(), Os: runtime.GOOS, Arch: runtime.GOARCH, + BuildTime: dockerversion.BUILDTIME, } if version.GreaterThanOrEqualTo("1.19") { diff --git a/api/types/types.go b/api/types/types.go index d54b48bc79..189325b617 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -139,6 +139,7 @@ type Version struct { Arch string KernelVersion string `json:",omitempty"` Experimental bool `json:",omitempty"` + BuildTime string `json:",omitempty"` } // GET "/info" diff --git a/hack/make.sh b/hack/make.sh index 2d6c7e5160..ad3eee2a5c 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -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 GITCOMMIT="$GITCOMMIT-dirty" fi + BUILDTIME=$(date -u) elif [ "$DOCKER_GITCOMMIT" ]; then GITCOMMIT="$DOCKER_GITCOMMIT" else diff --git a/hack/make/.go-autogen b/hack/make/.go-autogen index 81f38dc8da..52e2f571d8 100644 --- a/hack/make/.go-autogen +++ b/hack/make/.go-autogen @@ -10,6 +10,7 @@ package dockerversion var ( GITCOMMIT string = "$GITCOMMIT" VERSION string = "$VERSION" + BUILDTIME string = "$BUILDTIME" IAMSTATIC string = "${IAMSTATIC:-true}" INITSHA1 string = "$DOCKER_INITSHA1" diff --git a/integration-cli/docker_cli_version_test.go b/integration-cli/docker_cli_version_test.go index 3616da988f..e15caedb4c 100644 --- a/integration-cli/docker_cli_version_test.go +++ b/integration-cli/docker_cli_version_test.go @@ -15,23 +15,20 @@ func (s *DockerSuite) TestVersionEnsureSucceeds(c *check.C) { c.Fatalf("failed to execute docker version: %s, %v", out, err) } - stringsToCheck := []string{ - "Client version:", - "Client API version:", - "Go version (client):", - "Git commit (client):", - "OS/Arch (client):", - "Server version:", - "Server API version:", - "Go version (server):", - "Git commit (server):", - "OS/Arch (server):", + stringsToCheck := map[string]int{ + "Client:": 1, + "Server:": 1, + " Version:": 2, + " API version:": 2, + " Go version:": 2, + " Git commit:": 2, + " OS/Arch:": 2, + " Built:": 2, } - for _, linePrefix := range stringsToCheck { - if !strings.Contains(out, linePrefix) { - c.Errorf("couldn't find string %v in output", linePrefix) + for k, v := range stringsToCheck { + if strings.Count(out, k) != v { + c.Errorf("%v expected %d instances found %d", k, v, strings.Count(out, k)) } } - }