Browse Source

fix support for remote absolute path

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 7 months ago
parent
commit
6e35652182
3 changed files with 15 additions and 20 deletions
  1. 1 1
      go.mod
  2. 2 2
      go.sum
  3. 12 17
      pkg/compose/create.go

+ 1 - 1
go.mod

@@ -8,7 +8,7 @@ require (
 	github.com/Microsoft/go-winio v0.6.2
 	github.com/Microsoft/go-winio v0.6.2
 	github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
 	github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
 	github.com/buger/goterm v1.0.4
 	github.com/buger/goterm v1.0.4
-	github.com/compose-spec/compose-go/v2 v2.6.2-0.20250423090706-30ff01d36f76
+	github.com/compose-spec/compose-go/v2 v2.6.2-0.20250428082045-7eb3472a5a95
 	github.com/containerd/containerd/v2 v2.0.5
 	github.com/containerd/containerd/v2 v2.0.5
 	github.com/containerd/platforms v1.0.0-rc.1
 	github.com/containerd/platforms v1.0.0-rc.1
 	github.com/davecgh/go-spew v1.1.1
 	github.com/davecgh/go-spew v1.1.1

+ 2 - 2
go.sum

@@ -82,8 +82,8 @@ github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 h1:lkAMpLVBDaj17e
 github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
 github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
 github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
 github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
 github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
 github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
-github.com/compose-spec/compose-go/v2 v2.6.2-0.20250423090706-30ff01d36f76 h1:KZvD41eTRr9/n43zccAcGPBRgzHXdbLZY4IXSeJxqIw=
-github.com/compose-spec/compose-go/v2 v2.6.2-0.20250423090706-30ff01d36f76/go.mod h1:vPlkN0i+0LjLf9rv52lodNMUTJF5YHVfHVGLLIP67NA=
+github.com/compose-spec/compose-go/v2 v2.6.2-0.20250428082045-7eb3472a5a95 h1:lWMFXVkl+LkMdllYT4P/5snsB8JNhQoFnSsRX1pbX1o=
+github.com/compose-spec/compose-go/v2 v2.6.2-0.20250428082045-7eb3472a5a95/go.mod h1:vPlkN0i+0LjLf9rv52lodNMUTJF5YHVfHVGLLIP67NA=
 github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=
 github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=
 github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
 github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
 github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro=
 github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro=

+ 12 - 17
pkg/compose/create.go

@@ -27,6 +27,7 @@ import (
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 
 
+	"github.com/compose-spec/compose-go/v2/paths"
 	"github.com/compose-spec/compose-go/v2/types"
 	"github.com/compose-spec/compose-go/v2/types"
 	"github.com/docker/compose/v2/pkg/api"
 	"github.com/docker/compose/v2/pkg/api"
 	"github.com/docker/compose/v2/pkg/progress"
 	"github.com/docker/compose/v2/pkg/progress"
@@ -1126,28 +1127,22 @@ func isUnixAbs(p string) bool {
 }
 }
 
 
 func isWindowsAbs(p string) bool {
 func isWindowsAbs(p string) bool {
-	if strings.HasPrefix(p, "\\\\") {
-		return true
-	}
-	if len(p) > 2 && p[1] == ':' {
-		return p[2] == '\\'
-	}
-	return false
+	return paths.IsWindowsAbs(p)
 }
 }
 
 
 func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.Mount, error) {
 func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.Mount, error) {
 	source := volume.Source
 	source := volume.Source
-	// on windows, filepath.IsAbs(source) is false for unix style abs path like /var/run/docker.sock.
-	// do not replace these with  filepath.Abs(source) that will include a default drive.
-	if volume.Type == types.VolumeTypeBind && !filepath.IsAbs(source) && !strings.HasPrefix(source, "/") {
-		// volume source has already been prefixed with workdir if required, by compose-go project loader
-		var err error
-		source, err = filepath.Abs(source)
-		if err != nil {
-			return mount.Mount{}, err
+	switch volume.Type {
+	case types.VolumeTypeBind:
+		if !filepath.IsAbs(source) && !isUnixAbs(source) && !isWindowsAbs(source) {
+			// volume source has already been prefixed with workdir if required, by compose-go project loader
+			var err error
+			source, err = filepath.Abs(source)
+			if err != nil {
+				return mount.Mount{}, err
+			}
 		}
 		}
-	}
-	if volume.Type == types.VolumeTypeVolume {
+	case types.VolumeTypeVolume:
 		if volume.Source != "" {
 		if volume.Source != "" {
 			pVolume, ok := project.Volumes[volume.Source]
 			pVolume, ok := project.Volumes[volume.Source]
 			if ok {
 			if ok {