mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
display warning on the server in debug in version don't match
This commit is contained in:
parent
4576e11121
commit
7c7619ecf8
2 changed files with 11 additions and 23 deletions
7
api.go
7
api.go
|
@ -564,6 +564,13 @@ func ListenAndServe(addr string, srv *Server) error {
|
||||||
r.Path(localRoute).Methods(localMethod).HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
r.Path(localRoute).Methods(localMethod).HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
Debugf("Calling %s %s", localMethod, localRoute)
|
Debugf("Calling %s %s", localMethod, localRoute)
|
||||||
log.Println(r.Method, r.RequestURI)
|
log.Println(r.Method, r.RequestURI)
|
||||||
|
|
||||||
|
if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") {
|
||||||
|
userAgent := strings.Split(r.Header.Get("User-Agent"), "/")
|
||||||
|
if len(userAgent) == 2 && userAgent[1] != VERSION {
|
||||||
|
Debugf("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], VERSION)
|
||||||
|
}
|
||||||
|
}
|
||||||
json, err := localFct(srv, w, r)
|
json, err := localFct(srv, w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, err)
|
httpError(w, err)
|
||||||
|
|
27
commands.go
27
commands.go
|
@ -28,31 +28,8 @@ var (
|
||||||
GIT_COMMIT string
|
GIT_COMMIT string
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkRemoteVersion() error {
|
|
||||||
body, _, err := call("GET", "/version", nil)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Can't connect to docker daemon. Is 'docker -d' running on this host?")
|
|
||||||
}
|
|
||||||
|
|
||||||
var out ApiVersion
|
|
||||||
|
|
||||||
err = json.Unmarshal(body, &out)
|
|
||||||
if err != nil {
|
|
||||||
Debugf("Error unmarshal: body: %s, err: %s\n", body, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if out.Version != VERSION {
|
|
||||||
fmt.Fprintf(os.Stderr, "Warning: client and server don't have the same version (client: %s, server: %)", VERSION, out.Version)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseCommands(args ...string) error {
|
func ParseCommands(args ...string) error {
|
||||||
|
|
||||||
if err := checkRemoteVersion(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmds := map[string]func(args ...string) error{
|
cmds := map[string]func(args ...string) error{
|
||||||
"attach": CmdAttach,
|
"attach": CmdAttach,
|
||||||
"build": CmdBuild,
|
"build": CmdBuild,
|
||||||
|
@ -1177,6 +1154,7 @@ func call(method, path string, data interface{}) ([]byte, int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
}
|
}
|
||||||
|
req.Header.Set("User-Agent", "Docker-Client/"+VERSION)
|
||||||
if data != nil {
|
if data != nil {
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
} else if method == "POST" {
|
} else if method == "POST" {
|
||||||
|
@ -1184,6 +1162,9 @@ func call(method, path string, data interface{}) ([]byte, int, error) {
|
||||||
}
|
}
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "connection refused") {
|
||||||
|
return nil, -1, fmt.Errorf("Can't connect to docker daemon. Is 'docker -d' running on this host?")
|
||||||
|
}
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue