Skip to content

Commit 162cc24

Browse files
authored
Merge pull request #192 from ndeloof/tmpfs_size
allow tmpfs.size to be set in unit bytes
2 parents ff6c3ad + 4c39168 commit 162cc24

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

loader/full-struct_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
403403
{Source: "datavolume", Target: "/var/lib/mysql", Type: "volume", Volume: &types.ServiceVolumeVolume{}},
404404
{Source: filepath.Join(workingDir, "opt"), Target: "/opt", Consistency: "cached", Type: "bind"},
405405
{Target: "/opt", Type: "tmpfs", Tmpfs: &types.ServiceVolumeTmpfs{
406-
Size: int64(10000),
406+
Size: types.UnitBytes(10000),
407407
}},
408408
},
409409
WorkingDir: "/code",
@@ -866,7 +866,7 @@ func fullExampleYAML(workingDir, homeDir string) string {
866866
- type: tmpfs
867867
target: /opt
868868
tmpfs:
869-
size: 10000
869+
size: "10000"
870870
working_dir: /code
871871
x-bar: baz
872872
x-foo: bar
@@ -1503,7 +1503,7 @@ func fullExampleJSON(workingDir, homeDir string) string {
15031503
"type": "tmpfs",
15041504
"target": "/opt",
15051505
"tmpfs": {
1506-
"size": 10000
1506+
"size": "10000"
15071507
}
15081508
}
15091509
],

loader/interpolate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var interpolateTypeCastMapping = map[interp.Path]interp.Cast{
6767
servicePath("ulimits", interp.PathMatchAll, "soft"): toInt,
6868
servicePath("volumes", interp.PathMatchList, "read_only"): toBoolean,
6969
servicePath("volumes", interp.PathMatchList, "volume", "nocopy"): toBoolean,
70+
servicePath("volumes", interp.PathMatchList, "tmpfs", "size"): toUnitBytes,
7071
iPath("networks", interp.PathMatchAll, "external"): toBoolean,
7172
iPath("networks", interp.PathMatchAll, "internal"): toBoolean,
7273
iPath("networks", interp.PathMatchAll, "attachable"): toBoolean,

loader/loader_test.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package loader
1818

1919
import (
2020
"bytes"
21+
"fmt"
2122
"io/ioutil"
2223
"os"
2324
"sort"
@@ -928,29 +929,32 @@ func TestFullExample(t *testing.T) {
928929
}
929930

930931
func TestLoadTmpfsVolume(t *testing.T) {
931-
config, err := loadYAML(`
932+
for _, size := range []string{"1kb", "1024"} {
933+
yaml := fmt.Sprintf(`
932934
services:
933935
tmpfs:
934936
image: nginx:latest
935937
volumes:
936-
- type: tmpfs
937-
target: /app
938-
tmpfs:
939-
size: 10000
940-
`)
941-
assert.NilError(t, err)
938+
- type: tmpfs
939+
target: /app
940+
tmpfs:
941+
size: %s
942+
`, size)
943+
config, err := loadYAML(yaml)
944+
assert.NilError(t, err)
945+
946+
expected := types.ServiceVolumeConfig{
947+
Target: "/app",
948+
Type: "tmpfs",
949+
Tmpfs: &types.ServiceVolumeTmpfs{
950+
Size: types.UnitBytes(1024),
951+
},
952+
}
942953

943-
expected := types.ServiceVolumeConfig{
944-
Target: "/app",
945-
Type: "tmpfs",
946-
Tmpfs: &types.ServiceVolumeTmpfs{
947-
Size: int64(10000),
948-
},
954+
assert.Assert(t, is.Len(config.Services, 1))
955+
assert.Check(t, is.Len(config.Services[0].Volumes, 1))
956+
assert.Check(t, is.DeepEqual(expected, config.Services[0].Volumes[0]))
949957
}
950-
951-
assert.Assert(t, is.Len(config.Services, 1))
952-
assert.Check(t, is.Len(config.Services[0].Volumes, 1))
953-
assert.Check(t, is.DeepEqual(expected, config.Services[0].Volumes[0]))
954958
}
955959

956960
func TestLoadTmpfsVolumeAdditionalPropertyNotAllowed(t *testing.T) {

schema/compose-spec.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
"privileged": {"type": "boolean"},
332332
"profiles": {"$ref": "#/definitions/list_of_strings"},
333333
"pull_policy": {"type": "string", "enum": [
334-
"always", "never", "if_not_present", "build"
334+
"always", "never", "if_not_present", "build", "missing"
335335
]},
336336
"read_only": {"type": "boolean"},
337337
"restart": {"type": "string"},
@@ -367,6 +367,7 @@
367367
"stdin_open": {"type": "boolean"},
368368
"stop_grace_period": {"type": "string", "format": "duration"},
369369
"stop_signal": {"type": "string"},
370+
"storage_opt": {"type": "object"},
370371
"tmpfs": {"$ref": "#/definitions/string_or_list"},
371372
"tty": {"type": "boolean"},
372373
"ulimits": {
@@ -426,8 +427,10 @@
426427
"type": "object",
427428
"properties": {
428429
"size": {
429-
"type": "integer",
430-
"minimum": 0
430+
"oneOf": [
431+
{"type": "integer", "minimum": 0},
432+
{"type": "string"}
433+
]
431434
}
432435
},
433436
"additionalProperties": false,
@@ -599,12 +602,12 @@
599602
"items": {
600603
"type": "object",
601604
"properties": {
602-
"capabilities": {"$ref": "#/definitions/list_of_strings"},
603-
"count": {"type": ["string", "integer"]},
604-
"device_ids": {"$ref": "#/definitions/list_of_strings"},
605-
"driver":{"type": "string"},
606-
"options":{"$ref": "#/definitions/list_or_dict"}
607-
},
605+
"capabilities": {"$ref": "#/definitions/list_of_strings"},
606+
"count": {"type": ["string", "integer"]},
607+
"device_ids": {"$ref": "#/definitions/list_of_strings"},
608+
"driver":{"type": "string"},
609+
"options":{"$ref": "#/definitions/list_or_dict"}
610+
},
608611
"additionalProperties": false,
609612
"patternProperties": {"^x-": {}}
610613
}
@@ -810,4 +813,4 @@
810813
}
811814
}
812815
}
813-
}
816+
}

types/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ type ServiceVolumeVolume struct {
690690

691691
// ServiceVolumeTmpfs are options for a service volume of type tmpfs
692692
type ServiceVolumeTmpfs struct {
693-
Size int64 `yaml:",omitempty" json:"size,omitempty"`
693+
Size UnitBytes `yaml:",omitempty" json:"size,omitempty"`
694694

695695
Extensions map[string]interface{} `yaml:",inline" json:"-"`
696696
}

0 commit comments

Comments
 (0)