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
2 changes: 2 additions & 0 deletions cli/compose/convert/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package convert
import (
"errors"
"fmt"
"os"
"strings"

composetypes "github.com/docker/cli/cli/compose/types"
Expand Down Expand Up @@ -164,6 +165,7 @@ func handleTmpfsToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, e
if volume.Tmpfs != nil {
result.TmpfsOptions = &mount.TmpfsOptions{
SizeBytes: volume.Tmpfs.Size,
Mode: os.FileMode(volume.Tmpfs.Mode),
}
}
return result, nil
Expand Down
22 changes: 22 additions & 0 deletions cli/compose/convert/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,28 @@ func TestConvertTmpfsToMountVolume(t *testing.T) {
assert.Check(t, is.DeepEqual(expected, mnt))
}

func TestConvertTmpfsToMountVolumeWithMode(t *testing.T) {
config := composetypes.ServiceVolumeConfig{
Type: "tmpfs",
Target: "/foo/bar",
Tmpfs: &composetypes.ServiceVolumeTmpfs{
Size: 1000,
Mode: 0o1777,
},
}
expected := mount.Mount{
Type: mount.TypeTmpfs,
Target: "/foo/bar",
TmpfsOptions: &mount.TmpfsOptions{
SizeBytes: 1000,
Mode: 0o1777,
},
}
mnt, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, mnt))
}

func TestConvertTmpfsToMountVolumeWithSource(t *testing.T) {
config := composetypes.ServiceVolumeConfig{
Type: "tmpfs",
Expand Down
29 changes: 29 additions & 0 deletions cli/compose/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,35 @@ services:
assert.Check(t, is.DeepEqual(expected, config.Services[0].Volumes[0]))
}

func TestLoadTmpfsVolumeMode(t *testing.T) {
config, err := loadYAML(`
version: "3.6"
services:
tmpfs:
image: nginx:latest
volumes:
- type: tmpfs
target: /run
tmpfs:
size: 268435456
mode: 01777
`)
assert.NilError(t, err)

expected := types.ServiceVolumeConfig{
Target: "/run",
Type: "tmpfs",
Tmpfs: &types.ServiceVolumeTmpfs{
Size: int64(268435456),
Mode: 0o1777,
},
}

assert.Assert(t, is.Len(config.Services, 1))
assert.Check(t, is.Len(config.Services[0].Volumes, 1))
assert.Check(t, is.DeepEqual(expected, config.Services[0].Volumes[0]))
}

func TestLoadTmpfsVolumeAdditionalPropertyNotAllowed(t *testing.T) {
_, err := loadYAML(`
version: "3.5"
Expand Down
4 changes: 4 additions & 0 deletions cli/compose/schema/data/config_schema_v3.10.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@
"size": {
"type": "integer",
"minimum": 0
},
"mode": {
"type": "integer",
"minimum": 0
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cli/compose/schema/data/config_schema_v3.11.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@
"size": {
"type": "integer",
"minimum": 0
},
"mode": {
"type": "integer",
"minimum": 0
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cli/compose/schema/data/config_schema_v3.12.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@
"size": {
"type": "integer",
"minimum": 0
},
"mode": {
"type": "integer",
"minimum": 0
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cli/compose/schema/data/config_schema_v3.13.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@
"size": {
"type": "integer",
"minimum": 0
},
"mode": {
"type": "integer",
"minimum": 0
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cli/compose/schema/data/config_schema_v3.6.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@
"size": {
"type": "integer",
"minimum": 0
},
"mode": {
"type": "integer",
"minimum": 0
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cli/compose/schema/data/config_schema_v3.7.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@
"size": {
"type": "integer",
"minimum": 0
},
"mode": {
"type": "integer",
"minimum": 0
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cli/compose/schema/data/config_schema_v3.8.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@
"size": {
"type": "integer",
"minimum": 0
},
"mode": {
"type": "integer",
"minimum": 0
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cli/compose/schema/data/config_schema_v3.9.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@
"size": {
"type": "integer",
"minimum": 0
},
"mode": {
"type": "integer",
"minimum": 0
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/volumespec/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type ImageOpts struct {

// TmpFsOpts are options for a service volume of type tmpfs
type TmpFsOpts struct {
Size int64 `yaml:",omitempty" json:"size,omitempty"`
Size int64 `yaml:",omitempty" json:"size,omitempty"`
Mode uint32 `yaml:",omitempty" json:"mode,omitempty"`
}

// ClusterOpts are options for a service volume of type cluster.
Expand Down
Loading