From fb5ffe62de4f92e971a9999850f35e20568f29db Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 26 Nov 2018 17:22:57 -0500 Subject: [PATCH] add support for tmpfs --- drivers/docker/config.go | 20 +++++++++++++++++++- drivers/docker/driver_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/docker/config.go b/drivers/docker/config.go index 1d2ae281a31..33ce1b46589 100644 --- a/drivers/docker/config.go +++ b/drivers/docker/config.go @@ -253,6 +253,10 @@ var ( "bind_options": hclspec.NewBlock("bind_options", false, hclspec.NewObject(map[string]*hclspec.Spec{ "propagation": hclspec.NewAttr("propagation", "string", false), })), + "tmpfs_options": hclspec.NewBlock("tmpfs_options", false, hclspec.NewObject(map[string]*hclspec.Spec{ + "size": hclspec.NewAttr("size", "number", false), + "mode": hclspec.NewAttr("mode", "number", false), + })), "volume_options": hclspec.NewBlock("volume_options", false, hclspec.NewObject(map[string]*hclspec.Spec{ "no_copy": hclspec.NewAttr("no_copy", "bool", false), "labels": hclspec.NewBlockAttrs("labels", "string", false), @@ -364,6 +368,7 @@ type DockerMount struct { ReadOnly bool `codec:"readonly"` BindOptions DockerBindOptions `codec:"bind_options"` VolumeOptions DockerVolumeOptions `codec:"volume_options"` + TmpfsOptions DockerTmpfsOptions `codec:"tmpfs_options"` } func (m DockerMount) toDockerHostMount() (docker.HostMount, error) { @@ -394,8 +399,16 @@ func (m DockerMount) toDockerHostMount() (docker.HostMount, error) { hm.BindOptions = &docker.BindOptions{ Propagation: m.BindOptions.Propagation, } + case "tmpfs": + if m.Source != "" { + return hm, fmt.Errorf(`invalid source, must be "" for tmpfs`) + } + hm.TempfsOptions = &docker.TempfsOptions{ + SizeBytes: m.TmpfsOptions.SizeBytes, + Mode: m.TmpfsOptions.Mode, + } default: - return hm, fmt.Errorf(`invalid mount type, must be "bind" or "volume": %q`, m.Type) + return hm, fmt.Errorf(`invalid mount type, must be "bind", "volume", "tmpfs": %q`, m.Type) } return hm, nil @@ -411,6 +424,11 @@ type DockerBindOptions struct { Propagation string `codec:"propagation"` } +type DockerTmpfsOptions struct { + SizeBytes int64 `codec:"size"` + Mode int `codec:"mode"` +} + // DockerVolumeDriverConfig holds a map of volume driver specific options type DockerVolumeDriverConfig struct { Name string `codec:"name"` diff --git a/drivers/docker/driver_test.go b/drivers/docker/driver_test.go index f047155e126..b0568e08e56 100644 --- a/drivers/docker/driver_test.go +++ b/drivers/docker/driver_test.go @@ -1824,6 +1824,30 @@ func TestDockerDriver_MountsSerialization(t *testing.T) { }, }, }, + { + name: "basic tmpfs", + requiresVolumes: false, + passedMounts: []DockerMount{ + { + Type: "tmpfs", + Target: "/nomad", + TmpfsOptions: DockerTmpfsOptions{ + SizeBytes: 321, + Mode: 0666, + }, + }, + }, + expectedMounts: []docker.HostMount{ + { + Type: "tmpfs", + Target: "/nomad", + TempfsOptions: &docker.TempfsOptions{ + SizeBytes: 321, + Mode: 0666, + }, + }, + }, + }, } t.Run("with volumes enabled", func(t *testing.T) {