mirror of https://github.com/docker/cli.git
Merge pull request #824 from ethan-haynes/820-bind-mount-source-missing-error
added check for empty source in bind mount
This commit is contained in:
commit
cea4d37bca
|
@ -361,7 +361,9 @@ func LoadService(name string, serviceDict map[string]interface{}, workingDir str
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveVolumePaths(serviceConfig.Volumes, workingDir, lookupEnv)
|
if err := resolveVolumePaths(serviceConfig.Volumes, workingDir, lookupEnv); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return serviceConfig, nil
|
return serviceConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,12 +402,16 @@ func resolveEnvironment(serviceConfig *types.ServiceConfig, workingDir string, l
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveVolumePaths(volumes []types.ServiceVolumeConfig, workingDir string, lookupEnv template.Mapping) {
|
func resolveVolumePaths(volumes []types.ServiceVolumeConfig, workingDir string, lookupEnv template.Mapping) error {
|
||||||
for i, volume := range volumes {
|
for i, volume := range volumes {
|
||||||
if volume.Type != "bind" {
|
if volume.Type != "bind" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if volume.Source == "" {
|
||||||
|
return errors.New(`invalid mount config for type "bind": field Source must not be empty`)
|
||||||
|
}
|
||||||
|
|
||||||
filePath := expandUser(volume.Source, lookupEnv)
|
filePath := expandUser(volume.Source, lookupEnv)
|
||||||
// Check for a Unix absolute path first, to handle a Windows client
|
// Check for a Unix absolute path first, to handle a Windows client
|
||||||
// with a Unix daemon. This handles a Windows client connecting to a
|
// with a Unix daemon. This handles a Windows client connecting to a
|
||||||
|
@ -418,6 +424,7 @@ func resolveVolumePaths(volumes []types.ServiceVolumeConfig, workingDir string,
|
||||||
volume.Source = filePath
|
volume.Source = filePath
|
||||||
volumes[i] = volume
|
volumes[i] = volume
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make this more robust
|
// TODO: make this more robust
|
||||||
|
|
|
@ -895,6 +895,46 @@ services:
|
||||||
assert.Contains(t, err.Error(), "services.tmpfs.volumes.0 Additional property tmpfs is not allowed")
|
assert.Contains(t, err.Error(), "services.tmpfs.volumes.0 Additional property tmpfs is not allowed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadBindMountSourceMustNotBeEmpty(t *testing.T) {
|
||||||
|
_, err := loadYAML(`
|
||||||
|
version: "3.5"
|
||||||
|
services:
|
||||||
|
tmpfs:
|
||||||
|
image: nginx:latest
|
||||||
|
volumes:
|
||||||
|
- type: bind
|
||||||
|
target: /app
|
||||||
|
`)
|
||||||
|
require.EqualError(t, err, `invalid mount config for type "bind": field Source must not be empty`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLoadBindMountWithSource(t *testing.T) {
|
||||||
|
config, err := loadYAML(`
|
||||||
|
version: "3.5"
|
||||||
|
services:
|
||||||
|
bind:
|
||||||
|
image: nginx:latest
|
||||||
|
volumes:
|
||||||
|
- type: bind
|
||||||
|
target: /app
|
||||||
|
source: "."
|
||||||
|
`)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
workingDir, err := os.Getwd()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
expected := types.ServiceVolumeConfig{
|
||||||
|
Type: "bind",
|
||||||
|
Source: workingDir,
|
||||||
|
Target: "/app",
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Len(t, config.Services, 1)
|
||||||
|
assert.Len(t, config.Services[0].Volumes, 1)
|
||||||
|
assert.Equal(t, expected, config.Services[0].Volumes[0])
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadTmpfsVolumeSizeCanBeZero(t *testing.T) {
|
func TestLoadTmpfsVolumeSizeCanBeZero(t *testing.T) {
|
||||||
config, err := loadYAML(`
|
config, err := loadYAML(`
|
||||||
version: "3.6"
|
version: "3.6"
|
||||||
|
|
Loading…
Reference in New Issue