diff --git a/client/build_prune.go b/client/build_prune.go index ec17b5a6f3..a22e9685e2 100644 --- a/client/build_prune.go +++ b/client/build_prune.go @@ -8,7 +8,7 @@ import ( "strconv" "github.com/moby/moby/api/types/build" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" ) // BuildCachePruneOptions hold parameters to prune the build cache. diff --git a/client/client.go b/client/client.go index 02bfa87471..643dfbdf8f 100644 --- a/client/client.go +++ b/client/client.go @@ -56,7 +56,7 @@ import ( cerrdefs "github.com/containerd/errdefs" "github.com/docker/go-connections/sockets" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" ) diff --git a/client/errors.go b/client/errors.go index 81a9f4eb14..4980d7cadc 100644 --- a/client/errors.go +++ b/client/errors.go @@ -8,7 +8,7 @@ import ( cerrdefs "github.com/containerd/errdefs" "github.com/containerd/errdefs/pkg/errhttp" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" ) // errConnectionFailed implements an error returned when connection failed. diff --git a/client/image_list.go b/client/image_list.go index 955422c137..6df3c66e17 100644 --- a/client/image_list.go +++ b/client/image_list.go @@ -6,7 +6,7 @@ import ( "net/url" "github.com/moby/moby/api/types/image" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" ) // ImageList returns a list of images in the docker host. diff --git a/api/types/versions/compare.go b/client/pkg/versions/compare.go similarity index 100% rename from api/types/versions/compare.go rename to client/pkg/versions/compare.go diff --git a/api/types/versions/compare_test.go b/client/pkg/versions/compare_test.go similarity index 100% rename from api/types/versions/compare_test.go rename to client/pkg/versions/compare_test.go diff --git a/daemon/config/config.go b/daemon/config/config.go index 74ab57cfc9..73fb6c07c5 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -13,8 +13,8 @@ import ( "dario.cat/mergo" "github.com/containerd/log" - "github.com/moby/moby/api/types/versions" dopts "github.com/moby/moby/v2/daemon/internal/opts" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/pkg/opts" "github.com/moby/moby/v2/daemon/pkg/registry" "github.com/pkg/errors" diff --git a/vendor/github.com/moby/moby/api/types/versions/compare.go b/daemon/internal/versions/compare.go similarity index 100% rename from vendor/github.com/moby/moby/api/types/versions/compare.go rename to daemon/internal/versions/compare.go diff --git a/daemon/internal/versions/compare_test.go b/daemon/internal/versions/compare_test.go new file mode 100644 index 0000000000..c2b96869f7 --- /dev/null +++ b/daemon/internal/versions/compare_test.go @@ -0,0 +1,26 @@ +package versions + +import ( + "testing" +) + +func assertVersion(t *testing.T, a, b string, result int) { + if r := compare(a, b); r != result { + t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result) + } +} + +func TestCompareVersion(t *testing.T) { + assertVersion(t, "1.12", "1.12", 0) + assertVersion(t, "1.0.0", "1", 0) + assertVersion(t, "1", "1.0.0", 0) + assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1) + assertVersion(t, "1", "1.0.1", -1) + assertVersion(t, "1.0.1", "1", 1) + assertVersion(t, "1.0.1", "1.0.2", -1) + assertVersion(t, "1.0.2", "1.0.3", -1) + assertVersion(t, "1.0.3", "1.1", -1) + assertVersion(t, "1.1", "1.1.1", -1) + assertVersion(t, "1.1.1", "1.1.2", -1) + assertVersion(t, "1.1.2", "1.2", -1) +} diff --git a/daemon/server/middleware/version.go b/daemon/server/middleware/version.go index 27f31c9427..20fe1a4ab7 100644 --- a/daemon/server/middleware/version.go +++ b/daemon/server/middleware/version.go @@ -6,8 +6,8 @@ import ( "net/http" "runtime" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/config" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/httputils" ) diff --git a/daemon/server/router/build/build_routes.go b/daemon/server/router/build/build_routes.go index f06b272294..f408792fe2 100644 --- a/daemon/server/router/build/build_routes.go +++ b/daemon/server/router/build/build_routes.go @@ -21,8 +21,8 @@ import ( "github.com/moby/moby/api/types/build" "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/registry" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/internal/filters" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/buildbackend" "github.com/moby/moby/v2/daemon/server/httputils" "github.com/moby/moby/v2/pkg/ioutils" diff --git a/daemon/server/router/container/container_routes.go b/daemon/server/router/container/container_routes.go index 399f5a16f3..38bfc157f1 100644 --- a/daemon/server/router/container/container_routes.go +++ b/daemon/server/router/container/container_routes.go @@ -17,9 +17,9 @@ import ( "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/mount" "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/internal/filters" "github.com/moby/moby/v2/daemon/internal/runconfig" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/libnetwork/netlabel" networkSettings "github.com/moby/moby/v2/daemon/network" "github.com/moby/moby/v2/daemon/server/backend" diff --git a/daemon/server/router/container/exec.go b/daemon/server/router/container/exec.go index 8e9939a8bf..d4da27f2f7 100644 --- a/daemon/server/router/container/exec.go +++ b/daemon/server/router/container/exec.go @@ -10,8 +10,8 @@ import ( "github.com/moby/moby/api/pkg/stdcopy" "github.com/moby/moby/api/types" "github.com/moby/moby/api/types/container" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/internal/stdcopymux" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/backend" "github.com/moby/moby/v2/daemon/server/httputils" "github.com/moby/moby/v2/errdefs" diff --git a/daemon/server/router/container/inspect.go b/daemon/server/router/container/inspect.go index 6551ac1e3d..a22e017364 100644 --- a/daemon/server/router/container/inspect.go +++ b/daemon/server/router/container/inspect.go @@ -6,9 +6,9 @@ import ( "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/storage" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/internal/compat" "github.com/moby/moby/v2/daemon/internal/stringid" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/backend" "github.com/moby/moby/v2/daemon/server/httputils" "github.com/moby/moby/v2/internal/sliceutil" diff --git a/daemon/server/router/image/image_routes.go b/daemon/server/router/image/image_routes.go index f31fc4087f..4ddde92a1a 100644 --- a/daemon/server/router/image/image_routes.go +++ b/daemon/server/router/image/image_routes.go @@ -16,11 +16,11 @@ import ( "github.com/moby/moby/api/pkg/progress" "github.com/moby/moby/api/pkg/streamformatter" "github.com/moby/moby/api/types/registry" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/builder/remotecontext" "github.com/moby/moby/v2/daemon/internal/compat" "github.com/moby/moby/v2/daemon/internal/filters" "github.com/moby/moby/v2/daemon/internal/image" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/httputils" "github.com/moby/moby/v2/daemon/server/imagebackend" "github.com/moby/moby/v2/dockerversion" diff --git a/daemon/server/router/local.go b/daemon/server/router/local.go index 884c407186..4fae1cb9a2 100644 --- a/daemon/server/router/local.go +++ b/daemon/server/router/local.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/httputils" ) diff --git a/daemon/server/router/network/network_routes.go b/daemon/server/router/network/network_routes.go index accc584617..0fd81d2f0d 100644 --- a/daemon/server/router/network/network_routes.go +++ b/daemon/server/router/network/network_routes.go @@ -7,8 +7,8 @@ import ( "strings" "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/internal/filters" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/libnetwork" "github.com/moby/moby/v2/daemon/libnetwork/scope" dnetwork "github.com/moby/moby/v2/daemon/network" diff --git a/daemon/server/router/swarm/cluster_routes.go b/daemon/server/router/swarm/cluster_routes.go index 8a0405f68e..7b47198c99 100644 --- a/daemon/server/router/swarm/cluster_routes.go +++ b/daemon/server/router/swarm/cluster_routes.go @@ -9,9 +9,9 @@ import ( "github.com/containerd/log" "github.com/moby/moby/api/types/registry" types "github.com/moby/moby/api/types/swarm" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/internal/compat" "github.com/moby/moby/v2/daemon/internal/filters" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/backend" "github.com/moby/moby/v2/daemon/server/httputils" "github.com/moby/moby/v2/daemon/server/swarmbackend" diff --git a/daemon/server/router/swarm/helpers.go b/daemon/server/router/swarm/helpers.go index b5007d0c28..bf83028234 100644 --- a/daemon/server/router/swarm/helpers.go +++ b/daemon/server/router/swarm/helpers.go @@ -7,7 +7,7 @@ import ( basictypes "github.com/moby/moby/api/types" "github.com/moby/moby/api/types/swarm" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/backend" "github.com/moby/moby/v2/daemon/server/httputils" ) diff --git a/daemon/server/router/system/system_routes.go b/daemon/server/router/system/system_routes.go index a531cf28bf..49dbc6888f 100644 --- a/daemon/server/router/system/system_routes.go +++ b/daemon/server/router/system/system_routes.go @@ -16,10 +16,10 @@ import ( "github.com/moby/moby/api/types/registry" "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/api/types/system" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/internal/compat" "github.com/moby/moby/v2/daemon/internal/filters" "github.com/moby/moby/v2/daemon/internal/timestamp" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/backend" "github.com/moby/moby/v2/daemon/server/httputils" "github.com/moby/moby/v2/daemon/server/router/build" diff --git a/daemon/server/router/volume/volume_routes.go b/daemon/server/router/volume/volume_routes.go index 24d438bdd6..4e577a49d2 100644 --- a/daemon/server/router/volume/volume_routes.go +++ b/daemon/server/router/volume/volume_routes.go @@ -8,9 +8,9 @@ import ( cerrdefs "github.com/containerd/errdefs" "github.com/containerd/log" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/api/types/volume" "github.com/moby/moby/v2/daemon/internal/filters" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/httputils" "github.com/moby/moby/v2/daemon/server/volumebackend" "github.com/moby/moby/v2/daemon/volume/service/opts" diff --git a/daemon/server/server.go b/daemon/server/server.go index ad12584b46..e021cc4636 100644 --- a/daemon/server/server.go +++ b/daemon/server/server.go @@ -7,8 +7,8 @@ import ( "github.com/containerd/log" "github.com/gorilla/mux" "github.com/moby/moby/api/types/common" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/v2/daemon/internal/otelutil" + "github.com/moby/moby/v2/daemon/internal/versions" "github.com/moby/moby/v2/daemon/server/httpstatus" "github.com/moby/moby/v2/daemon/server/httputils" "github.com/moby/moby/v2/daemon/server/middleware" diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index c2ff91c38c..5279d9e005 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -21,7 +21,7 @@ import ( "github.com/moby/buildkit/frontend/dockerfile/command" "github.com/moby/go-archive" "github.com/moby/go-archive/compression" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" "github.com/moby/moby/v2/integration-cli/cli" "github.com/moby/moby/v2/integration-cli/cli/build" "github.com/moby/moby/v2/internal/testutil" diff --git a/integration-cli/docker_cli_push_test.go b/integration-cli/docker_cli_push_test.go index b0c0094a60..345df8aa24 100644 --- a/integration-cli/docker_cli_push_test.go +++ b/integration-cli/docker_cli_push_test.go @@ -12,7 +12,7 @@ import ( "testing" "github.com/distribution/reference" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" "github.com/moby/moby/v2/integration-cli/cli" "github.com/moby/moby/v2/integration-cli/cli/build" "golang.org/x/sync/errgroup" diff --git a/integration-cli/docker_cli_swarm_test.go b/integration-cli/docker_cli_swarm_test.go index c578f1fa42..7f05bdad4e 100644 --- a/integration-cli/docker_cli_swarm_test.go +++ b/integration-cli/docker_cli_swarm_test.go @@ -20,8 +20,8 @@ import ( "github.com/cloudflare/cfssl/helpers" "github.com/moby/moby/api/types/swarm" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/client" + "github.com/moby/moby/client/pkg/versions" "github.com/moby/moby/v2/daemon/libnetwork/driverapi" "github.com/moby/moby/v2/daemon/libnetwork/ipamapi" remoteipam "github.com/moby/moby/v2/daemon/libnetwork/ipams/remote/api" diff --git a/integration/container/create_test.go b/integration/container/create_test.go index c0dc2b37a1..dc51ed8c72 100644 --- a/integration/container/create_test.go +++ b/integration/container/create_test.go @@ -15,9 +15,9 @@ import ( "github.com/moby/moby/api/types/common" "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/client" "github.com/moby/moby/client/pkg/stringid" + "github.com/moby/moby/client/pkg/versions" "github.com/moby/moby/v2/daemon/pkg/oci" testContainer "github.com/moby/moby/v2/integration/internal/container" net "github.com/moby/moby/v2/integration/internal/network" diff --git a/integration/container/list_test.go b/integration/container/list_test.go index 7cc2ae14c4..63253ef033 100644 --- a/integration/container/list_test.go +++ b/integration/container/list_test.go @@ -7,8 +7,8 @@ import ( "time" containertypes "github.com/moby/moby/api/types/container" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/client" + "github.com/moby/moby/client/pkg/versions" "github.com/moby/moby/v2/integration/internal/container" "github.com/moby/moby/v2/internal/testutil" "github.com/moby/moby/v2/internal/testutil/request" diff --git a/integration/container/mounts_linux_test.go b/integration/container/mounts_linux_test.go index 3d5c157d8a..dab4c4a7b3 100644 --- a/integration/container/mounts_linux_test.go +++ b/integration/container/mounts_linux_test.go @@ -11,8 +11,8 @@ import ( containertypes "github.com/moby/moby/api/types/container" mounttypes "github.com/moby/moby/api/types/mount" "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/client" + "github.com/moby/moby/client/pkg/versions" "github.com/moby/moby/v2/daemon/config" "github.com/moby/moby/v2/daemon/volume" "github.com/moby/moby/v2/integration/internal/container" diff --git a/integration/network/network_linux_test.go b/integration/network/network_linux_test.go index 425fc06ea4..955f9e84c7 100644 --- a/integration/network/network_linux_test.go +++ b/integration/network/network_linux_test.go @@ -12,8 +12,8 @@ import ( "time" networktypes "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/client" + "github.com/moby/moby/client/pkg/versions" "github.com/moby/moby/v2/daemon/libnetwork/netlabel" "github.com/moby/moby/v2/integration/internal/container" "github.com/moby/moby/v2/integration/internal/network" diff --git a/integration/volume/mount_test.go b/integration/volume/mount_test.go index 699c3550f5..5cd6a4b661 100644 --- a/integration/volume/mount_test.go +++ b/integration/volume/mount_test.go @@ -12,8 +12,8 @@ import ( containertypes "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/mount" "github.com/moby/moby/api/types/network" - "github.com/moby/moby/api/types/versions" "github.com/moby/moby/client" + "github.com/moby/moby/client/pkg/versions" "github.com/moby/moby/v2/daemon/volume/safepath" "github.com/moby/moby/v2/integration/internal/container" "github.com/moby/moby/v2/internal/testutil/fakecontext" diff --git a/vendor/github.com/moby/moby/client/build_prune.go b/vendor/github.com/moby/moby/client/build_prune.go index ec17b5a6f3..a22e9685e2 100644 --- a/vendor/github.com/moby/moby/client/build_prune.go +++ b/vendor/github.com/moby/moby/client/build_prune.go @@ -8,7 +8,7 @@ import ( "strconv" "github.com/moby/moby/api/types/build" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" ) // BuildCachePruneOptions hold parameters to prune the build cache. diff --git a/vendor/github.com/moby/moby/client/client.go b/vendor/github.com/moby/moby/client/client.go index 02bfa87471..643dfbdf8f 100644 --- a/vendor/github.com/moby/moby/client/client.go +++ b/vendor/github.com/moby/moby/client/client.go @@ -56,7 +56,7 @@ import ( cerrdefs "github.com/containerd/errdefs" "github.com/docker/go-connections/sockets" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" ) diff --git a/vendor/github.com/moby/moby/client/errors.go b/vendor/github.com/moby/moby/client/errors.go index 81a9f4eb14..4980d7cadc 100644 --- a/vendor/github.com/moby/moby/client/errors.go +++ b/vendor/github.com/moby/moby/client/errors.go @@ -8,7 +8,7 @@ import ( cerrdefs "github.com/containerd/errdefs" "github.com/containerd/errdefs/pkg/errhttp" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" ) // errConnectionFailed implements an error returned when connection failed. diff --git a/vendor/github.com/moby/moby/client/image_list.go b/vendor/github.com/moby/moby/client/image_list.go index 955422c137..6df3c66e17 100644 --- a/vendor/github.com/moby/moby/client/image_list.go +++ b/vendor/github.com/moby/moby/client/image_list.go @@ -6,7 +6,7 @@ import ( "net/url" "github.com/moby/moby/api/types/image" - "github.com/moby/moby/api/types/versions" + "github.com/moby/moby/client/pkg/versions" ) // ImageList returns a list of images in the docker host. diff --git a/vendor/github.com/moby/moby/client/pkg/versions/compare.go b/vendor/github.com/moby/moby/client/pkg/versions/compare.go new file mode 100644 index 0000000000..1a0325c7ed --- /dev/null +++ b/vendor/github.com/moby/moby/client/pkg/versions/compare.go @@ -0,0 +1,65 @@ +package versions + +import ( + "strconv" + "strings" +) + +// compare compares two version strings +// returns -1 if v1 < v2, 1 if v1 > v2, 0 otherwise. +func compare(v1, v2 string) int { + if v1 == v2 { + return 0 + } + var ( + currTab = strings.Split(v1, ".") + otherTab = strings.Split(v2, ".") + ) + + maxVer := len(currTab) + if len(otherTab) > maxVer { + maxVer = len(otherTab) + } + for i := 0; i < maxVer; i++ { + var currInt, otherInt int + + if len(currTab) > i { + currInt, _ = strconv.Atoi(currTab[i]) + } + if len(otherTab) > i { + otherInt, _ = strconv.Atoi(otherTab[i]) + } + if currInt > otherInt { + return 1 + } + if otherInt > currInt { + return -1 + } + } + return 0 +} + +// LessThan checks if a version is less than another +func LessThan(v, other string) bool { + return compare(v, other) == -1 +} + +// LessThanOrEqualTo checks if a version is less than or equal to another +func LessThanOrEqualTo(v, other string) bool { + return compare(v, other) <= 0 +} + +// GreaterThan checks if a version is greater than another +func GreaterThan(v, other string) bool { + return compare(v, other) == 1 +} + +// GreaterThanOrEqualTo checks if a version is greater than or equal to another +func GreaterThanOrEqualTo(v, other string) bool { + return compare(v, other) >= 0 +} + +// Equal checks if a version is equal to another +func Equal(v, other string) bool { + return compare(v, other) == 0 +} diff --git a/vendor/modules.txt b/vendor/modules.txt index f389a26043..8a45181d65 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -961,7 +961,6 @@ github.com/moby/moby/api/types/registry github.com/moby/moby/api/types/storage github.com/moby/moby/api/types/swarm github.com/moby/moby/api/types/system -github.com/moby/moby/api/types/versions github.com/moby/moby/api/types/volume # github.com/moby/moby/client v0.1.0-beta.2 => ./client ## explicit; go 1.23.0 @@ -970,6 +969,7 @@ github.com/moby/moby/client/internal github.com/moby/moby/client/internal/timestamp github.com/moby/moby/client/pkg/jsonmessage github.com/moby/moby/client/pkg/stringid +github.com/moby/moby/client/pkg/versions # github.com/moby/patternmatcher v0.6.0 ## explicit; go 1.19 github.com/moby/patternmatcher