mirror of https://github.com/docker/docs.git
Port 'docker version' to the engine API
This commit is contained in:
parent
869a11bc93
commit
de35b346d1
3
api.go
3
api.go
|
@ -140,7 +140,8 @@ func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reque
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVersion(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func getVersion(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
return writeJSON(w, http.StatusOK, srv.DockerVersion())
|
srv.Eng.ServeHTTP(w, r)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func postContainersKill(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func postContainersKill(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
|
|
|
@ -95,12 +95,6 @@ type (
|
||||||
IP string
|
IP string
|
||||||
}
|
}
|
||||||
|
|
||||||
APIVersion struct {
|
|
||||||
Version string
|
|
||||||
GitCommit string `json:",omitempty"`
|
|
||||||
GoVersion string `json:",omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
APIWait struct {
|
APIWait struct {
|
||||||
StatusCode int
|
StatusCode int
|
||||||
}
|
}
|
||||||
|
|
25
commands.go
25
commands.go
|
@ -11,6 +11,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/archive"
|
"github.com/dotcloud/docker/archive"
|
||||||
"github.com/dotcloud/docker/auth"
|
"github.com/dotcloud/docker/auth"
|
||||||
|
"github.com/dotcloud/docker/engine"
|
||||||
"github.com/dotcloud/docker/registry"
|
"github.com/dotcloud/docker/registry"
|
||||||
"github.com/dotcloud/docker/term"
|
"github.com/dotcloud/docker/term"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
|
@ -391,26 +392,24 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var out APIVersion
|
out := engine.NewOutput()
|
||||||
err = json.Unmarshal(body, &out)
|
remoteVersion, err := out.AddEnv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Errorf("Error unmarshal: body: %s, err: %s\n", body, err)
|
utils.Errorf("Error reading remote version: %s\n", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if out.Version != "" {
|
if _, err := out.Write(body); err != nil {
|
||||||
fmt.Fprintf(cli.out, "Server version: %s\n", out.Version)
|
utils.Errorf("Error reading remote version: %s\n", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
if out.GitCommit != "" {
|
out.Close()
|
||||||
fmt.Fprintf(cli.out, "Git commit (server): %s\n", out.GitCommit)
|
fmt.Fprintf(cli.out, "Server version: %s\n", remoteVersion.Get("Version"))
|
||||||
}
|
fmt.Fprintf(cli.out, "Git commit (server): %s\n", remoteVersion.Get("GitCommit"))
|
||||||
if out.GoVersion != "" {
|
fmt.Fprintf(cli.out, "Go version (server): %s\n", remoteVersion.Get("GoVersion"))
|
||||||
fmt.Fprintf(cli.out, "Go version (server): %s\n", out.GoVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
release := utils.GetReleaseVersion()
|
release := utils.GetReleaseVersion()
|
||||||
if release != "" {
|
if release != "" {
|
||||||
fmt.Fprintf(cli.out, "Last stable version: %s", release)
|
fmt.Fprintf(cli.out, "Last stable version: %s", release)
|
||||||
if (VERSION != "" || out.Version != "") && (strings.Trim(VERSION, "-dev") != release || strings.Trim(out.Version, "-dev") != release) {
|
if (VERSION != "" || remoteVersion.Exists("Version")) && (strings.Trim(VERSION, "-dev") != release || strings.Trim(remoteVersion.Get("Version"), "-dev") != release) {
|
||||||
fmt.Fprintf(cli.out, ", please update docker")
|
fmt.Fprintf(cli.out, ", please update docker")
|
||||||
}
|
}
|
||||||
fmt.Fprintf(cli.out, "\n")
|
fmt.Fprintf(cli.out, "\n")
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker"
|
"github.com/dotcloud/docker"
|
||||||
|
"github.com/dotcloud/docker/engine"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
@ -35,12 +36,18 @@ func TestGetVersion(t *testing.T) {
|
||||||
}
|
}
|
||||||
assertHttpNotError(r, t)
|
assertHttpNotError(r, t)
|
||||||
|
|
||||||
v := &docker.APIVersion{}
|
out := engine.NewOutput()
|
||||||
if err = json.Unmarshal(r.Body.Bytes(), v); err != nil {
|
v, err := out.AddEnv()
|
||||||
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if v.Version != docker.VERSION {
|
if _, err := io.Copy(out, r.Body); err != nil {
|
||||||
t.Errorf("Expected version %s, %s found", docker.VERSION, v.Version)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
out.Close()
|
||||||
|
expected := docker.VERSION
|
||||||
|
if result := v.Get("Version"); result != expected {
|
||||||
|
t.Errorf("Expected version %s, %s found", expected, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,14 +118,6 @@ func (srv *Server) ListenAndServe(job *engine.Job) engine.Status {
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) DockerVersion() APIVersion {
|
|
||||||
return APIVersion{
|
|
||||||
Version: VERSION,
|
|
||||||
GitCommit: GITCOMMIT,
|
|
||||||
GoVersion: runtime.Version(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// simpleVersionInfo is a simple implementation of
|
// simpleVersionInfo is a simple implementation of
|
||||||
// the interface VersionInfo, which is used
|
// the interface VersionInfo, which is used
|
||||||
// to provide version information for some product,
|
// to provide version information for some product,
|
||||||
|
|
Loading…
Reference in New Issue