Merge pull request #1531 from docker/mount_options

ignore mount options which don't match type
This commit is contained in:
Nicolas De loof 2021-04-13 14:02:58 +02:00 committed by GitHub
commit 28ef6ccf1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 3 deletions

View File

@ -774,18 +774,50 @@ func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.
}
}
bind, vol, tmpfs := buildMountOptions(volume)
return mount.Mount{
Type: mount.Type(volume.Type),
Source: source,
Target: volume.Target,
ReadOnly: volume.ReadOnly,
Consistency: mount.Consistency(volume.Consistency),
BindOptions: buildBindOption(volume.Bind),
VolumeOptions: buildVolumeOptions(volume.Volume),
TmpfsOptions: buildTmpfsOptions(volume.Tmpfs),
BindOptions: bind,
VolumeOptions: vol,
TmpfsOptions: tmpfs,
}, nil
}
func buildMountOptions(volume types.ServiceVolumeConfig) (*mount.BindOptions, *mount.VolumeOptions, *mount.TmpfsOptions) {
switch volume.Type {
case "bind":
if volume.Volume != nil {
logrus.Warnf("mount of type `bind` should not define `volume` option")
}
if volume.Tmpfs != nil {
logrus.Warnf("mount of type `tmpfs` should not define `tmpfs` option")
}
return buildBindOption(volume.Bind), nil, nil
case "volume":
if volume.Bind != nil {
logrus.Warnf("mount of type `volume` should not define `bind` option")
}
if volume.Tmpfs != nil {
logrus.Warnf("mount of type `volume` should not define `tmpfs` option")
}
return nil, buildVolumeOptions(volume.Volume), nil
case "tmpfs":
if volume.Bind != nil {
logrus.Warnf("mount of type `tmpfs` should not define `bind` option")
}
if volume.Tmpfs != nil {
logrus.Warnf("mount of type `tmpfs` should not define `volumeZ` option")
}
return nil, nil, buildTmpfsOptions(volume.Tmpfs)
}
return nil, nil, nil
}
func buildBindOption(bind *types.ServiceVolumeBind) *mount.BindOptions {
if bind == nil {
return nil