Browse code

api: generalize version information to any platform component

This change adds a Platform struct with a Name field and a general
Components field to the Version API type. This will allow API
consumers to show version information for the whole platform and
it will allow API providers to set the versions for the various
components of the platform.

All changes here are backwards compatible.

Signed-off-by: Tibor Vass <tibor@docker.com>

Tibor Vass authored on 2017/12/05 23:29:37
Showing 6 changed files
... ...
@@ -53,7 +53,8 @@ DOCKER_ENVS := \
53 53
 	-e http_proxy \
54 54
 	-e https_proxy \
55 55
 	-e no_proxy \
56
-	-e VERSION
56
+	-e VERSION \
57
+	-e PLATFORM
57 58
 # note: we _cannot_ add "-e DOCKER_BUILDTAGS" here because even if it's unset in the shell, that would shadow the "ENV DOCKER_BUILDTAGS" set in our Dockerfile, which is very important for our official builds
58 59
 
59 60
 # to allow `make BIND_DIR=. shell` or `make BIND_DIR= test`
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"net/http"
7 7
 	"time"
8 8
 
9
-	"github.com/docker/docker/api"
10 9
 	"github.com/docker/docker/api/server/httputils"
11 10
 	"github.com/docker/docker/api/types"
12 11
 	"github.com/docker/docker/api/types/events"
... ...
@@ -65,7 +64,6 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
65 65
 
66 66
 func (s *systemRouter) getVersion(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
67 67
 	info := s.backend.SystemVersion()
68
-	info.APIVersion = api.DefaultVersion
69 68
 
70 69
 	return httputils.WriteJSON(w, http.StatusOK, info)
71 70
 }
... ...
@@ -107,9 +107,21 @@ type Ping struct {
107 107
 	Experimental bool
108 108
 }
109 109
 
110
+// ComponentVersion describes the version information for a specific component.
111
+type ComponentVersion struct {
112
+	Name    string
113
+	Version string
114
+	Details map[string]string `json:",omitempty"`
115
+}
116
+
110 117
 // Version contains response of Engine API:
111 118
 // GET "/version"
112 119
 type Version struct {
120
+	Platform   struct{ Name string } `json:",omitempty"`
121
+	Components []ComponentVersion    `json:",omitempty"`
122
+
123
+	// The following fields are deprecated, they relate to the Engine component and are kept for backwards compatibility
124
+
113 125
 	Version       string
114 126
 	APIVersion    string `json:"ApiVersion"`
115 127
 	MinAPIVersion string `json:"MinAPIVersion,omitempty"`
... ...
@@ -154,24 +154,46 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
154 154
 
155 155
 // SystemVersion returns version information about the daemon.
156 156
 func (daemon *Daemon) SystemVersion() types.Version {
157
+	kernelVersion := "<unknown>"
158
+	if kv, err := kernel.GetKernelVersion(); err != nil {
159
+		logrus.Warnf("Could not get kernel version: %v", err)
160
+	} else {
161
+		kernelVersion = kv.String()
162
+	}
163
+
157 164
 	v := types.Version{
165
+		Components: []types.ComponentVersion{
166
+			{
167
+				Name:    "Engine",
168
+				Version: dockerversion.Version,
169
+				Details: map[string]string{
170
+					"GitCommit":     dockerversion.GitCommit,
171
+					"ApiVersion":    api.DefaultVersion,
172
+					"MinAPIVersion": api.MinVersion,
173
+					"GoVersion":     runtime.Version(),
174
+					"Os":            runtime.GOOS,
175
+					"Arch":          runtime.GOARCH,
176
+					"BuildTime":     dockerversion.BuildTime,
177
+					"KernelVersion": kernelVersion,
178
+					"Experimental":  fmt.Sprintf("%t", daemon.configStore.Experimental),
179
+				},
180
+			},
181
+		},
182
+
183
+		// Populate deprecated fields for older clients
158 184
 		Version:       dockerversion.Version,
159 185
 		GitCommit:     dockerversion.GitCommit,
186
+		APIVersion:    api.DefaultVersion,
160 187
 		MinAPIVersion: api.MinVersion,
161 188
 		GoVersion:     runtime.Version(),
162 189
 		Os:            runtime.GOOS,
163 190
 		Arch:          runtime.GOARCH,
164 191
 		BuildTime:     dockerversion.BuildTime,
192
+		KernelVersion: kernelVersion,
165 193
 		Experimental:  daemon.configStore.Experimental,
166 194
 	}
167 195
 
168
-	kernelVersion := "<unknown>"
169
-	if kv, err := kernel.GetKernelVersion(); err != nil {
170
-		logrus.Warnf("Could not get kernel version: %v", err)
171
-	} else {
172
-		kernelVersion = kv.String()
173
-	}
174
-	v.KernelVersion = kernelVersion
196
+	v.Platform.Name = dockerversion.PlatformName
175 197
 
176 198
 	return v
177 199
 }
... ...
@@ -13,4 +13,5 @@ const (
13 13
 	ContainerdCommitID string = "library-import"
14 14
 	RuncCommitID       string = "library-import"
15 15
 	InitCommitID       string = "library-import"
16
+	PlatformName       string = ""
16 17
 )
... ...
@@ -18,6 +18,7 @@ const (
18 18
 	BuildTime          string = "$BUILDTIME"
19 19
 	IAmStatic          string = "${IAMSTATIC:-true}"
20 20
 	ContainerdCommitID string = "${CONTAINERD_COMMIT}"
21
+	PlatformName       string = "${PLATFORM}"
21 22
 )
22 23
 
23 24
 // AUTOGENERATED FILE; see /go/src/github.com/docker/docker/hack/make/.go-autogen