api: move types/versions to client/pkg and daemon/internal

This change moves the api/types/versions package out into client and daemon versions.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
This commit is contained in:
Austin Vazquez
2025-10-23 19:01:49 -05:00
parent e62b820f36
commit f40e1a7582
36 changed files with 122 additions and 31 deletions

View File

@@ -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.

View File

@@ -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"
)

View File

@@ -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.

View File

@@ -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.

View File

@@ -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"

View File

@@ -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)
}

View File

@@ -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"
)

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"
)

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"
)

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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.

View File

@@ -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"
)

View File

@@ -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.

View File

@@ -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.

View File

@@ -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
}

2
vendor/modules.txt vendored
View File

@@ -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