Browse Source

Merge pull request #1117 from dotcloud/add_last_version-feature

Add last stable version in `docker version`
Guillaume J. Charmes 12 years ago
parent
commit
ffcba1236c
2 changed files with 25 additions and 0 deletions
  1. 9 0
      commands.go
  2. 16 0
      utils/utils.go

+ 9 - 0
commands.go

@@ -448,6 +448,15 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
 	if out.GoVersion != "" {
 		fmt.Fprintf(cli.out, "Go version: %s\n", out.GoVersion)
 	}
+
+	release := utils.GetReleaseVersion()
+	if release != "" {
+		fmt.Fprintf(cli.out, "Last stable version: %s", release)
+		if strings.Trim(VERSION, "-dev") != release || strings.Trim(out.Version, "-dev") != release {
+			fmt.Fprintf(cli.out, ", please update docker")
+		}
+		fmt.Fprintf(cli.out, "\n")
+	}
 	return nil
 }
 

+ 16 - 0
utils/utils.go

@@ -730,6 +730,22 @@ func ParseHost(host string, port int, addr string) string {
 	return fmt.Sprintf("tcp://%s:%d", host, port)
 }
 
+func GetReleaseVersion() string {
+	resp, err := http.Get("http://get.docker.io/latest")
+	if err != nil {
+		return ""
+	}
+	defer resp.Body.Close()
+	if resp.ContentLength > 24 || resp.StatusCode != 200 {
+		return ""
+	}
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		return ""
+	}
+	return strings.TrimSpace(string(body))
+}
+
 // Get a repos name and returns the right reposName + tag
 // The tag can be confusing because of a port in a repository name.
 //     Ex: localhost.localdomain:5000/samalba/hipache:latest