mirror of https://github.com/docker/compose.git
Moved bind mode creation to getBindMode function
Added unit tests for all uses cases. Signed-off-by: Tymoteusz Blazejczyk <tymoteusz.blazejczyk@tymonx.com>
This commit is contained in:
parent
9d0421a929
commit
9f06a02eb5
|
@ -719,14 +719,7 @@ MOUNTS:
|
||||||
if m.Type == mount.TypeBind || m.Type == mount.TypeNamedPipe {
|
if m.Type == mount.TypeBind || m.Type == mount.TypeNamedPipe {
|
||||||
for _, v := range service.Volumes {
|
for _, v := range service.Volumes {
|
||||||
if v.Target == m.Target && v.Bind != nil && v.Bind.CreateHostPath {
|
if v.Target == m.Target && v.Bind != nil && v.Bind.CreateHostPath {
|
||||||
mode := "rw"
|
binds = append(binds, fmt.Sprintf("%s:%s:%s", m.Source, m.Target, getBindMode(v.Bind, m.ReadOnly)))
|
||||||
if m.ReadOnly {
|
|
||||||
mode = "ro"
|
|
||||||
}
|
|
||||||
if v.Bind.SELinux != "" {
|
|
||||||
mode += "," + v.Bind.SELinux
|
|
||||||
}
|
|
||||||
binds = append(binds, fmt.Sprintf("%s:%s:%s", m.Source, m.Target, mode))
|
|
||||||
continue MOUNTS
|
continue MOUNTS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -736,6 +729,23 @@ MOUNTS:
|
||||||
return volumeMounts, binds, mounts, nil
|
return volumeMounts, binds, mounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBindMode(bind *types.ServiceVolumeBind, readOnly bool) string {
|
||||||
|
mode := "rw"
|
||||||
|
|
||||||
|
if readOnly {
|
||||||
|
mode = "ro"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch bind.SELinux {
|
||||||
|
case types.SELinuxShared:
|
||||||
|
mode += ",z"
|
||||||
|
case types.SELinuxPrivate:
|
||||||
|
mode += ",Z"
|
||||||
|
}
|
||||||
|
|
||||||
|
return mode
|
||||||
|
}
|
||||||
|
|
||||||
func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) {
|
func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) {
|
||||||
var mounts = map[string]mount.Mount{}
|
var mounts = map[string]mount.Mount{}
|
||||||
if inherit != nil {
|
if inherit != nil {
|
||||||
|
|
|
@ -142,3 +142,12 @@ func TestBuildContainerMountOptions(t *testing.T) {
|
||||||
assert.Equal(t, mounts[0].Target, "/var/myvolume1")
|
assert.Equal(t, mounts[0].Target, "/var/myvolume1")
|
||||||
assert.Equal(t, mounts[1].Target, "/var/myvolume2")
|
assert.Equal(t, mounts[1].Target, "/var/myvolume2")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetBindMode(t *testing.T) {
|
||||||
|
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{}, false), "rw")
|
||||||
|
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{}, true), "ro")
|
||||||
|
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{SELinux: composetypes.SELinuxShared}, false), "rw,z")
|
||||||
|
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{SELinux: composetypes.SELinuxPrivate}, false), "rw,Z")
|
||||||
|
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{SELinux: composetypes.SELinuxShared}, true), "ro,z")
|
||||||
|
assert.Equal(t, getBindMode(&composetypes.ServiceVolumeBind{SELinux: composetypes.SELinuxPrivate}, true), "ro,Z")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue