From 3916dafe17df45b34a6caf3cb33caef6db24936d Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Tue, 5 Dec 2017 15:29:37 +0100 Subject: [PATCH 1/3] 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 Upstream-commit: 9152e63290e4a4e586b811cce39082efc649b912 Component: engine --- components/engine/Makefile | 3 +- .../api/server/router/system/system_routes.go | 2 - components/engine/api/types/types.go | 12 +++++ components/engine/daemon/info.go | 46 ++++++++++++++----- .../engine/dockerversion/version_lib.go | 1 + components/engine/hack/make/.go-autogen | 1 + 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/components/engine/Makefile b/components/engine/Makefile index 32988150c7..6f5145a026 100644 --- a/components/engine/Makefile +++ b/components/engine/Makefile @@ -53,7 +53,8 @@ DOCKER_ENVS := \ -e http_proxy \ -e https_proxy \ -e no_proxy \ - -e VERSION + -e VERSION \ + -e PLATFORM # 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 # to allow `make BIND_DIR=. shell` or `make BIND_DIR= test` diff --git a/components/engine/api/server/router/system/system_routes.go b/components/engine/api/server/router/system/system_routes.go index 8f6aecd77a..535956d65f 100644 --- a/components/engine/api/server/router/system/system_routes.go +++ b/components/engine/api/server/router/system/system_routes.go @@ -6,7 +6,6 @@ import ( "net/http" "time" - "github.com/docker/docker/api" "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/events" @@ -65,7 +64,6 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht func (s *systemRouter) getVersion(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { info := s.backend.SystemVersion() - info.APIVersion = api.DefaultVersion return httputils.WriteJSON(w, http.StatusOK, info) } diff --git a/components/engine/api/types/types.go b/components/engine/api/types/types.go index f7ac772971..7814e6b934 100644 --- a/components/engine/api/types/types.go +++ b/components/engine/api/types/types.go @@ -107,9 +107,21 @@ type Ping struct { Experimental bool } +// ComponentVersion describes the version information for a specific component. +type ComponentVersion struct { + Name string + Version string + Details map[string]string `json:",omitempty"` +} + // Version contains response of Engine API: // GET "/version" type Version struct { + Platform struct{ Name string } `json:",omitempty"` + Components []ComponentVersion `json:",omitempty"` + + // The following fields are deprecated, they relate to the Engine component and are kept for backwards compatibility + Version string APIVersion string `json:"ApiVersion"` MinAPIVersion string `json:"MinAPIVersion,omitempty"` diff --git a/components/engine/daemon/info.go b/components/engine/daemon/info.go index b14e7ba809..bbb027ed54 100644 --- a/components/engine/daemon/info.go +++ b/components/engine/daemon/info.go @@ -154,24 +154,46 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) { // SystemVersion returns version information about the daemon. func (daemon *Daemon) SystemVersion() types.Version { - v := types.Version{ - Version: dockerversion.Version, - GitCommit: dockerversion.GitCommit, - MinAPIVersion: api.MinVersion, - GoVersion: runtime.Version(), - Os: runtime.GOOS, - Arch: runtime.GOARCH, - BuildTime: dockerversion.BuildTime, - Experimental: daemon.configStore.Experimental, - } - kernelVersion := "" if kv, err := kernel.GetKernelVersion(); err != nil { logrus.Warnf("Could not get kernel version: %v", err) } else { kernelVersion = kv.String() } - v.KernelVersion = kernelVersion + + v := types.Version{ + Components: []types.ComponentVersion{ + { + Name: "Engine", + Version: dockerversion.Version, + Details: map[string]string{ + "GitCommit": dockerversion.GitCommit, + "ApiVersion": api.DefaultVersion, + "MinAPIVersion": api.MinVersion, + "GoVersion": runtime.Version(), + "Os": runtime.GOOS, + "Arch": runtime.GOARCH, + "BuildTime": dockerversion.BuildTime, + "KernelVersion": kernelVersion, + "Experimental": fmt.Sprintf("%t", daemon.configStore.Experimental), + }, + }, + }, + + // Populate deprecated fields for older clients + Version: dockerversion.Version, + GitCommit: dockerversion.GitCommit, + APIVersion: api.DefaultVersion, + MinAPIVersion: api.MinVersion, + GoVersion: runtime.Version(), + Os: runtime.GOOS, + Arch: runtime.GOARCH, + BuildTime: dockerversion.BuildTime, + KernelVersion: kernelVersion, + Experimental: daemon.configStore.Experimental, + } + + v.Platform.Name = dockerversion.PlatformName return v } diff --git a/components/engine/dockerversion/version_lib.go b/components/engine/dockerversion/version_lib.go index 33f77d3ce6..72f48939d6 100644 --- a/components/engine/dockerversion/version_lib.go +++ b/components/engine/dockerversion/version_lib.go @@ -13,4 +13,5 @@ const ( ContainerdCommitID string = "library-import" RuncCommitID string = "library-import" InitCommitID string = "library-import" + PlatformName string = "" ) diff --git a/components/engine/hack/make/.go-autogen b/components/engine/hack/make/.go-autogen index b68e3a7534..850c3ec9ac 100644 --- a/components/engine/hack/make/.go-autogen +++ b/components/engine/hack/make/.go-autogen @@ -18,6 +18,7 @@ const ( BuildTime string = "$BUILDTIME" IAmStatic string = "${IAMSTATIC:-true}" ContainerdCommitID string = "${CONTAINERD_COMMIT}" + PlatformName string = "${PLATFORM}" ) // AUTOGENERATED FILE; see /go/src/github.com/docker/docker/hack/make/.go-autogen From 947ed56f66143d7592c156bf0ef97e90664b3b0b Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Wed, 6 Dec 2017 21:29:22 +0100 Subject: [PATCH 2/3] Adjust swagger definitions Signed-off-by: Tibor Vass Upstream-commit: 87ebfa11f66d2109054ad3024217a5101b45aa8c Component: engine --- components/engine/api/swagger.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/components/engine/api/swagger.yaml b/components/engine/api/swagger.yaml index 96386e0599..de45301b06 100644 --- a/components/engine/api/swagger.yaml +++ b/components/engine/api/swagger.yaml @@ -6764,6 +6764,28 @@ paths: schema: type: "object" properties: + Platform: + type: "object" + required: [Name] + properties: + Name: + type: "string" + Components: + type: "array" + items: + type: "object" + x-go-name: ComponentVersion + required: [Name, Version] + properties: + Name: + type: "string" + Version: + type: "string" + x-nullable: false + Details: + type: "object" + x-nullable: true + Version: type: "string" ApiVersion: From 00a55a319dd5b74c408da211850eddfaf3258ea3 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Wed, 6 Dec 2017 22:02:30 +0100 Subject: [PATCH 3/3] Fix windows Signed-off-by: Tibor Vass Upstream-commit: cb8283a6e95f33a93fab0044ca4306cf468faf8c Component: engine --- components/engine/hack/make.ps1 | 2 +- components/engine/hack/make/.go-autogen.ps1 | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/engine/hack/make.ps1 b/components/engine/hack/make.ps1 index 3380a5b693..42a2b319fa 100644 --- a/components/engine/hack/make.ps1 +++ b/components/engine/hack/make.ps1 @@ -365,7 +365,7 @@ Try { # Run autogen if building binaries or running unit tests. if ($Client -or $Daemon -or $TestUnit) { Write-Host "INFO: Invoking autogen..." - Try { .\hack\make\.go-autogen.ps1 -CommitString $gitCommit -DockerVersion $dockerVersion } + Try { .\hack\make\.go-autogen.ps1 -CommitString $gitCommit -DockerVersion $dockerVersion -Platform "$env:PLATFORM" } Catch [Exception] { Throw $_ } } diff --git a/components/engine/hack/make/.go-autogen.ps1 b/components/engine/hack/make/.go-autogen.ps1 index 768badb6a5..cc14e9ee9d 100644 --- a/components/engine/hack/make/.go-autogen.ps1 +++ b/components/engine/hack/make/.go-autogen.ps1 @@ -14,7 +14,8 @@ param( [Parameter(Mandatory=$true)][string]$CommitString, - [Parameter(Mandatory=$true)][string]$DockerVersion + [Parameter(Mandatory=$true)][string]$DockerVersion, + [Parameter(Mandatory=$false)][string]$Platform ) $ErrorActionPreference = "Stop" @@ -43,6 +44,7 @@ const ( GitCommit string = "'+$CommitString+'" Version string = "'+$DockerVersion+'" BuildTime string = "'+$buildDateTime+'" + PlatformName string = "'+$Platform+'" ) // AUTOGENERATED FILE; see hack\make\.go-autogen.ps1