Merge pull request #29859 from thaJeztah/1.13-fix-anonymous-volumes
[1.13] fix anonymous volumes
This commit is contained in:
commit
f335200410
2 changed files with 44 additions and 2 deletions
|
@ -348,6 +348,12 @@ func convertVolumeToMount(
|
|||
// TODO: split Windows path mappings properly
|
||||
parts := strings.SplitN(volumeSpec, ":", 3)
|
||||
|
||||
for _, part := range parts {
|
||||
if strings.TrimSpace(part) == "" {
|
||||
return mount.Mount{}, fmt.Errorf("invalid volume: %s", volumeSpec)
|
||||
}
|
||||
}
|
||||
|
||||
switch len(parts) {
|
||||
case 3:
|
||||
source = parts[0]
|
||||
|
@ -358,8 +364,14 @@ func convertVolumeToMount(
|
|||
target = parts[1]
|
||||
case 1:
|
||||
target = parts[0]
|
||||
default:
|
||||
return mount.Mount{}, fmt.Errorf("invald volume: %s", volumeSpec)
|
||||
}
|
||||
|
||||
if source == "" {
|
||||
// Anonymous volume
|
||||
return mount.Mount{
|
||||
Type: mount.TypeVolume,
|
||||
Target: target,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TODO: catch Windows paths here
|
||||
|
|
30
cli/command/stack/deploy_test.go
Normal file
30
cli/command/stack/deploy_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
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)
|
||||
}
|
||||
|
||||
func TestConvertVolumeToMountInvalidFormat(t *testing.T) {
|
||||
namespace := namespace{name: "foo"}
|
||||
invalids := []string{"::", "::cc", ":bb:", "aa::", "aa::cc", "aa:bb:", " : : ", " : :cc", " :bb: ", "aa: : ", "aa: :cc", "aa:bb: "}
|
||||
for _, vol := range invalids {
|
||||
_, err := convertVolumeToMount(vol, map[string]composetypes.VolumeConfig{}, namespace)
|
||||
assert.Error(t, err, "invalid volume: "+vol)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue