From 12c9de37e9ea6fc2f2fb752fb9d3fe387d3dd06a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 31 Oct 2025 01:44:19 +0100 Subject: [PATCH] api/types: move Version to api/types/system Signed-off-by: Sebastiaan van Stijn --- api/types/system/version_response.go | 58 +++++++++++++++++++ api/types/types.go | 27 --------- client/version.go | 6 +- daemon/info.go | 7 +-- daemon/info_unix.go | 23 ++++---- daemon/info_windows.go | 3 +- daemon/server/router/system/backend.go | 3 +- integration/system/version_test.go | 4 +- .../moby/api/types/system/version_response.go | 58 +++++++++++++++++++ .../github.com/moby/moby/api/types/types.go | 27 --------- vendor/github.com/moby/moby/client/version.go | 6 +- 11 files changed, 140 insertions(+), 82 deletions(-) create mode 100644 api/types/system/version_response.go create mode 100644 vendor/github.com/moby/moby/api/types/system/version_response.go diff --git a/api/types/system/version_response.go b/api/types/system/version_response.go new file mode 100644 index 0000000000..61cd1b6e2f --- /dev/null +++ b/api/types/system/version_response.go @@ -0,0 +1,58 @@ +package system + +// VersionResponse contains information about the Docker server host. +// GET "/version" +type VersionResponse struct { + // Platform is the platform (product name) the server is running on. + Platform PlatformInfo `json:",omitempty"` + + // Version is the version of the daemon. + Version string + + // APIVersion is the highest API version supported by the server. + APIVersion string `json:"ApiVersion"` + + // MinAPIVersion is the minimum API version the server supports. + MinAPIVersion string `json:"MinAPIVersion,omitempty"` + + // Os is the operating system the server runs on. + Os string + + // Arch is the hardware architecture the server runs on. + Arch string + + // Components contains version information for the components making + // up the server. Information in this field is for informational + // purposes, and not part of the API contract. + Components []ComponentVersion `json:",omitempty"` + + // The following fields are deprecated, they relate to the Engine component and are kept for backwards compatibility + + GitCommit string `json:",omitempty"` + GoVersion string `json:",omitempty"` + KernelVersion string `json:",omitempty"` + Experimental bool `json:",omitempty"` + BuildTime string `json:",omitempty"` +} + +// PlatformInfo holds information about the platform (product name) the +// server is running on. +type PlatformInfo struct { + // Name is the name of the platform (for example, "Docker Engine - Community", + // or "Docker Desktop 4.49.0 (208003)") + Name string +} + +// ComponentVersion describes the version information for a specific component. +type ComponentVersion struct { + Name string + Version string + + // Details contains Key/value pairs of strings with additional information + // about the component. These values are intended for informational purposes + // only, and their content is not defined, and not part of the API + // specification. + // + // These messages can be printed by the client as information to the user. + Details map[string]string `json:",omitempty"` +} diff --git a/api/types/types.go b/api/types/types.go index c74cec0b29..a89befdda4 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -16,30 +16,3 @@ const ( // MediaTypeJSONSequence is the MIME-Type for JSON Text Sequences (RFC7464). MediaTypeJSONSequence = "application/json-seq" ) - -// 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"` - GitCommit string - GoVersion string - Os string - Arch string - KernelVersion string `json:",omitempty"` - Experimental bool `json:",omitempty"` - BuildTime string `json:",omitempty"` -} diff --git a/client/version.go b/client/version.go index 478da11e47..7fa5a3fa09 100644 --- a/client/version.go +++ b/client/version.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" - "github.com/moby/moby/api/types" + "github.com/moby/moby/api/types/system" ) // ServerVersionOptions specifies options for the server version request. @@ -41,7 +41,7 @@ type ServerVersionResult struct { // Components contains version information for the components making // up the server. Information in this field is for informational // purposes, and not part of the API contract. - Components []types.ComponentVersion + Components []system.ComponentVersion } // PlatformInfo holds information about the platform (product name) the @@ -60,7 +60,7 @@ func (cli *Client) ServerVersion(ctx context.Context, _ ServerVersionOptions) (S return ServerVersionResult{}, err } - var v types.Version + var v system.VersionResponse err = json.NewDecoder(resp.Body).Decode(&v) if err != nil { return ServerVersionResult{}, err diff --git a/daemon/info.go b/daemon/info.go index baee31c6f3..05a1c6de02 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -11,7 +11,6 @@ import ( "github.com/containerd/containerd/v2/pkg/tracing" "github.com/containerd/log" - "github.com/moby/moby/api/types" "github.com/moby/moby/api/types/system" "github.com/moby/moby/v2/daemon/command/debug" "github.com/moby/moby/v2/daemon/config" @@ -101,14 +100,14 @@ func (daemon *Daemon) SystemInfo(ctx context.Context) (*system.Info, error) { // Anything else should be logged and ignored because this is looking up // multiple things and is often used for debugging. // The only case valid early return is when the caller doesn't want the result anymore (ie context cancelled). -func (daemon *Daemon) SystemVersion(ctx context.Context) (types.Version, error) { +func (daemon *Daemon) SystemVersion(ctx context.Context) (system.VersionResponse, error) { defer metrics.StartTimer(metrics.HostInfoFunctions.WithValues("system_version"))() kernelVer := kernelVersion(ctx) cfg := daemon.config() - v := types.Version{ - Components: []types.ComponentVersion{ + v := system.VersionResponse{ + Components: []system.ComponentVersion{ { Name: "Engine", Version: dockerversion.Version, diff --git a/daemon/info_unix.go b/daemon/info_unix.go index 9456f40e05..87ecb8302f 100644 --- a/daemon/info_unix.go +++ b/daemon/info_unix.go @@ -13,7 +13,6 @@ import ( runcoptions "github.com/containerd/containerd/api/types/runc/options" "github.com/containerd/log" - "github.com/moby/moby/api/types" containertypes "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/system" "github.com/moby/moby/v2/daemon/config" @@ -158,7 +157,7 @@ func (daemon *Daemon) fillPlatformInfo(ctx context.Context, v *system.Info, sysI return nil } -func (daemon *Daemon) fillPlatformVersion(ctx context.Context, v *types.Version, cfg *configStore) error { +func (daemon *Daemon) fillPlatformVersion(ctx context.Context, v *system.VersionResponse, cfg *configStore) error { if err := daemon.populateContainerdVersion(ctx, v); err != nil { return err } @@ -215,7 +214,7 @@ func (daemon *Daemon) populateInitCommit(ctx context.Context, v *system.Info, cf return nil } -func (daemon *Daemon) fillRootlessVersion(ctx context.Context, v *types.Version) error { +func (daemon *Daemon) fillRootlessVersion(ctx context.Context, v *system.VersionResponse) error { if !rootless.RunningWithRootlessKit() { return nil } @@ -227,7 +226,7 @@ func (daemon *Daemon) fillRootlessVersion(ctx context.Context, v *types.Version) if err != nil { return errors.Wrap(err, "failed to retrieve RootlessKit version") } - rlV := types.ComponentVersion{ + rlV := system.ComponentVersion{ Name: "rootlesskit", Version: rlInfo.Version, Details: map[string]string{ @@ -266,7 +265,7 @@ func (daemon *Daemon) fillRootlessVersion(ctx context.Context, v *types.Version) log.G(ctx).WithError(err).Warn("Failed to parse slirp4netns version") return nil } - v.Components = append(v.Components, types.ComponentVersion{ + v.Components = append(v.Components, system.ComponentVersion{ Name: "slirp4netns", Version: ver, Details: map[string]string{ @@ -288,7 +287,7 @@ func (daemon *Daemon) fillRootlessVersion(ctx context.Context, v *types.Version) log.G(ctx).WithError(err).Warn("Failed to retrieve vpnkit version") return nil } - v.Components = append(v.Components, types.ComponentVersion{ + v.Components = append(v.Components, system.ComponentVersion{ Name: "vpnkit", Version: strings.TrimSpace(strings.TrimSpace(string(out))), }) @@ -428,7 +427,7 @@ func (daemon *Daemon) populateContainerdCommit(ctx context.Context, v *system.Co return nil } -func (daemon *Daemon) populateContainerdVersion(ctx context.Context, v *types.Version) error { +func (daemon *Daemon) populateContainerdVersion(ctx context.Context, v *system.VersionResponse) error { rv, err := daemon.containerd.Version(ctx) if err != nil { if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { @@ -438,7 +437,7 @@ func (daemon *Daemon) populateContainerdVersion(ctx context.Context, v *types.Ve return nil } - v.Components = append(v.Components, types.ComponentVersion{ + v.Components = append(v.Components, system.ComponentVersion{ Name: "containerd", Version: rv.Version, Details: map[string]string{ @@ -448,12 +447,12 @@ func (daemon *Daemon) populateContainerdVersion(ctx context.Context, v *types.Ve return nil } -func populateRuncVersion(cfg *configStore, v *types.Version) error { +func populateRuncVersion(cfg *configStore, v *system.VersionResponse) error { _, ver, commit, err := parseDefaultRuntimeVersion(&cfg.Runtimes) if err != nil { return err } - v.Components = append(v.Components, types.ComponentVersion{ + v.Components = append(v.Components, system.ComponentVersion{ Name: cfg.Runtimes.Default, Version: ver, Details: map[string]string{ @@ -463,7 +462,7 @@ func populateRuncVersion(cfg *configStore, v *types.Version) error { return nil } -func populateInitVersion(ctx context.Context, cfg *configStore, v *types.Version) error { +func populateInitVersion(ctx context.Context, cfg *configStore, v *system.VersionResponse) error { initBinary, err := cfg.LookupInitPath() if err != nil { log.G(ctx).WithError(err).Warn("Failed to find docker-init") @@ -484,7 +483,7 @@ func populateInitVersion(ctx context.Context, cfg *configStore, v *types.Version log.G(ctx).WithError(err).Warnf("failed to parse %s version", initBinary) return nil } - v.Components = append(v.Components, types.ComponentVersion{ + v.Components = append(v.Components, system.ComponentVersion{ Name: filepath.Base(initBinary), Version: ver, Details: map[string]string{ diff --git a/daemon/info_windows.go b/daemon/info_windows.go index bfb14efebb..607a973b2e 100644 --- a/daemon/info_windows.go +++ b/daemon/info_windows.go @@ -3,7 +3,6 @@ package daemon import ( "context" - "github.com/moby/moby/api/types" "github.com/moby/moby/api/types/system" "github.com/moby/moby/v2/daemon/config" "github.com/moby/moby/v2/pkg/sysinfo" @@ -18,7 +17,7 @@ WARNING: Feature flag "windows-dns-proxy" has been removed, forwarding to extern return nil } -func (daemon *Daemon) fillPlatformVersion(ctx context.Context, v *types.Version, cfg *configStore) error { +func (daemon *Daemon) fillPlatformVersion(ctx context.Context, v *system.VersionResponse, cfg *configStore) error { return nil } diff --git a/daemon/server/router/system/backend.go b/daemon/server/router/system/backend.go index 24354a9741..381ca1b63c 100644 --- a/daemon/server/router/system/backend.go +++ b/daemon/server/router/system/backend.go @@ -4,7 +4,6 @@ import ( "context" "time" - "github.com/moby/moby/api/types" "github.com/moby/moby/api/types/build" "github.com/moby/moby/api/types/events" "github.com/moby/moby/api/types/registry" @@ -18,7 +17,7 @@ import ( // system specific functionality. type Backend interface { SystemInfo(context.Context) (*system.Info, error) - SystemVersion(context.Context) (types.Version, error) + SystemVersion(context.Context) (system.VersionResponse, error) SystemDiskUsage(ctx context.Context, opts backend.DiskUsageOptions) (*backend.DiskUsage, error) SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan any) UnsubscribeFromEvents(chan any) diff --git a/integration/system/version_test.go b/integration/system/version_test.go index 0c3a3e7680..c05f88bf25 100644 --- a/integration/system/version_test.go +++ b/integration/system/version_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/moby/moby/api/types" + "github.com/moby/moby/api/types/system" "github.com/moby/moby/client" "github.com/moby/moby/v2/internal/testutil/request" "gotest.tools/v3/assert" @@ -21,7 +21,7 @@ func TestVersion(t *testing.T) { assert.NilError(t, err) assert.Check(t, len(version.Components) > 0, "expected at least one component in version.Components") - var engine types.ComponentVersion + var engine system.ComponentVersion var found bool for _, comp := range version.Components { diff --git a/vendor/github.com/moby/moby/api/types/system/version_response.go b/vendor/github.com/moby/moby/api/types/system/version_response.go new file mode 100644 index 0000000000..61cd1b6e2f --- /dev/null +++ b/vendor/github.com/moby/moby/api/types/system/version_response.go @@ -0,0 +1,58 @@ +package system + +// VersionResponse contains information about the Docker server host. +// GET "/version" +type VersionResponse struct { + // Platform is the platform (product name) the server is running on. + Platform PlatformInfo `json:",omitempty"` + + // Version is the version of the daemon. + Version string + + // APIVersion is the highest API version supported by the server. + APIVersion string `json:"ApiVersion"` + + // MinAPIVersion is the minimum API version the server supports. + MinAPIVersion string `json:"MinAPIVersion,omitempty"` + + // Os is the operating system the server runs on. + Os string + + // Arch is the hardware architecture the server runs on. + Arch string + + // Components contains version information for the components making + // up the server. Information in this field is for informational + // purposes, and not part of the API contract. + Components []ComponentVersion `json:",omitempty"` + + // The following fields are deprecated, they relate to the Engine component and are kept for backwards compatibility + + GitCommit string `json:",omitempty"` + GoVersion string `json:",omitempty"` + KernelVersion string `json:",omitempty"` + Experimental bool `json:",omitempty"` + BuildTime string `json:",omitempty"` +} + +// PlatformInfo holds information about the platform (product name) the +// server is running on. +type PlatformInfo struct { + // Name is the name of the platform (for example, "Docker Engine - Community", + // or "Docker Desktop 4.49.0 (208003)") + Name string +} + +// ComponentVersion describes the version information for a specific component. +type ComponentVersion struct { + Name string + Version string + + // Details contains Key/value pairs of strings with additional information + // about the component. These values are intended for informational purposes + // only, and their content is not defined, and not part of the API + // specification. + // + // These messages can be printed by the client as information to the user. + Details map[string]string `json:",omitempty"` +} diff --git a/vendor/github.com/moby/moby/api/types/types.go b/vendor/github.com/moby/moby/api/types/types.go index c74cec0b29..a89befdda4 100644 --- a/vendor/github.com/moby/moby/api/types/types.go +++ b/vendor/github.com/moby/moby/api/types/types.go @@ -16,30 +16,3 @@ const ( // MediaTypeJSONSequence is the MIME-Type for JSON Text Sequences (RFC7464). MediaTypeJSONSequence = "application/json-seq" ) - -// 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"` - GitCommit string - GoVersion string - Os string - Arch string - KernelVersion string `json:",omitempty"` - Experimental bool `json:",omitempty"` - BuildTime string `json:",omitempty"` -} diff --git a/vendor/github.com/moby/moby/client/version.go b/vendor/github.com/moby/moby/client/version.go index 478da11e47..7fa5a3fa09 100644 --- a/vendor/github.com/moby/moby/client/version.go +++ b/vendor/github.com/moby/moby/client/version.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" - "github.com/moby/moby/api/types" + "github.com/moby/moby/api/types/system" ) // ServerVersionOptions specifies options for the server version request. @@ -41,7 +41,7 @@ type ServerVersionResult struct { // Components contains version information for the components making // up the server. Information in this field is for informational // purposes, and not part of the API contract. - Components []types.ComponentVersion + Components []system.ComponentVersion } // PlatformInfo holds information about the platform (product name) the @@ -60,7 +60,7 @@ func (cli *Client) ServerVersion(ctx context.Context, _ ServerVersionOptions) (S return ServerVersionResult{}, err } - var v types.Version + var v system.VersionResponse err = json.NewDecoder(resp.Body).Decode(&v) if err != nil { return ServerVersionResult{}, err