Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/compose/convert/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func handleTmpfsToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, e
if volume.Tmpfs != nil {
result.TmpfsOptions = &mount.TmpfsOptions{
SizeBytes: volume.Tmpfs.Size,
RawOptions: volume.Tmpfs.Options,
}
}
return result, nil
Expand Down
18 changes: 18 additions & 0 deletions cli/compose/convert/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,21 @@ func TestConvertTmpfsToMountVolumeWithSource(t *testing.T) {
_, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
assert.Error(t, err, "invalid tmpfs source, source must be empty")
}

func TestConvertTmpfsToMountVolumeWithExecOption(t *testing.T) {
config := composetypes.ServiceVolumeConfig{
Type: "tmpfs",
Target: "/foo/bar",
Tmpfs: &composetypes.ServiceVolumeTmpfs{
Options: "exec",
},
}
expected := mount.Mount{
Type: mount.TypeTmpfs,
Target: "/foo/bar",
TmpfsOptions: &mount.TmpfsOptions{RawOptions: "exec"},
}
mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, mount))
}
1 change: 1 addition & 0 deletions cli/compose/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ type ServiceVolumeVolume struct {
// ServiceVolumeTmpfs are options for a service volume of type tmpfs
type ServiceVolumeTmpfs struct {
Size int64 `yaml:",omitempty"`
Options string `yaml:",omitempty"`
}

// FileReferenceConfig for a reference to a swarm file object
Expand Down
9 changes: 9 additions & 0 deletions opts/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ func (m *MountOpt) Set(value string) error {
return fmt.Errorf("invalid value for %s: %s", key, value)
}
tmpfsOptions().Mode = os.FileMode(ui64)
case "tmpfs-opt":
opt := strings.ToLower(value)
validOpts := map[string]bool {
"exec": true,
"noexec": true,
}
if _, ok := validOpts[opt]; ok {
tmpfsOptions().RawOptions = opt
}
default:
return fmt.Errorf("unexpected key '%s' in '%s'", key, field)
}
Expand Down
24 changes: 24 additions & 0 deletions opts/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,27 @@ func TestMountOptSetTmpfsError(t *testing.T) {
assert.ErrorContains(t, m.Set("type=tmpfs,target=/foo,tmpfs-mode=foo"), "invalid value for tmpfs-mode")
assert.ErrorContains(t, m.Set("type=tmpfs"), "target is required")
}

func TestMountOptSetTmpfsExecOpt(t *testing.T) {
for _, testcase := range []struct{
opts string
expected string
}{
{"type=tmpfs,target=/target,tmpfs-opt=exec", "exec"},
{"type=tmpfs,target=/target,tmpfs-opt=noexec", "noexec"},
} {
var mount MountOpt

assert.NilError(t, mount.Set(testcase.opts))

mounts := mount.Value()
assert.Assert(t, is.Len(mounts, 1))
assert.Check(t, is.DeepEqual(mounttypes.Mount{
Type: mounttypes.TypeTmpfs,
Target: "/target",
TmpfsOptions: &mounttypes.TmpfsOptions{
RawOptions: testcase.expected,
},
}, mounts[0]))
}
}
3 changes: 3 additions & 0 deletions vendor/github.com/docker/docker/api/types/mount/mount.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.