Browse Source

fix conversion of anonymous volumes in compose-file

the `convertVolumeToMount()` function did not take
anonymous volumes into account when converting
volume specifications to bind-mounts.

this resulted in the conversion to try to
look up an empty "source" volume, which
lead to an error;

    undefined volume:

this patch distinguishes "anonymous"
volumes from bind-mounts and named-volumes,
and skips further processing if no source
is defined (i.e. the volume is "anonymous").

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 8 years ago
parent
commit
36c0b59149
2 changed files with 30 additions and 1 deletions
  1. 9 1
      cli/command/stack/deploy.go
  2. 21 0
      cli/command/stack/deploy_test.go

+ 9 - 1
cli/command/stack/deploy.go

@@ -359,7 +359,15 @@ func convertVolumeToMount(
 	case 1:
 		target = parts[0]
 	default:
-		return mount.Mount{}, fmt.Errorf("invald volume: %s", volumeSpec)
+		return mount.Mount{}, fmt.Errorf("invalid volume: %s", volumeSpec)
+	}
+
+	if source == "" {
+		// Anonymous volume
+		return mount.Mount{
+			Type:   mount.TypeVolume,
+			Target: target,
+		}, nil
 	}
 
 	// TODO: catch Windows paths here

+ 21 - 0
cli/command/stack/deploy_test.go

@@ -0,0 +1,21 @@
+package stack
+
+import (
+	"testing"
+
+	composetypes "github.com/aanand/compose-file/types"
+	"github.com/docker/docker/api/types/mount"
+	"github.com/docker/docker/pkg/testutil/assert"
+)
+
+func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
+	stackVolumes := map[string]composetypes.VolumeConfig{}
+	namespace := namespace{name:"foo"}
+	expected := mount.Mount{
+		Type:   mount.TypeVolume,
+		Target: "/foo/bar",
+	}
+	mnt, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace)
+	assert.NilError(t, err)
+	assert.DeepEqual(t, mnt, expected)
+}