From 397aa20dfcc7de7e140f82e0dc178dce9dcfe6f0 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 10 Jan 2018 12:16:59 -0800 Subject: [PATCH] Support legacy tmpfs mounts Signed-off-by: Joffrey F --- compose/config/types.py | 4 ++++ compose/service.py | 10 ++++++++-- tests/integration/service_test.py | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/compose/config/types.py b/compose/config/types.py index daf25f700..5e1087858 100644 --- a/compose/config/types.py +++ b/compose/config/types.py @@ -183,6 +183,10 @@ class MountSpec(object): def is_named_volume(self): return self.type == 'volume' and self.source + @property + def is_tmpfs(self): + return self.type == 'tmpfs' + @property def external(self): return self.source diff --git a/compose/service.py b/compose/service.py index cc08ec274..420eb3f09 100644 --- a/compose/service.py +++ b/compose/service.py @@ -834,8 +834,14 @@ class Service(object): if version_gte(self.client.api_version, '1.30'): override_options['mounts'] = [build_mount(v) for v in container_mounts] or None else: - override_options['binds'].extend(m.legacy_repr() for m in container_mounts) - container_options['volumes'].update((m.target, {}) for m in container_mounts) + # Workaround for 3.2 format + self.options['tmpfs'] = self.options.get('tmpfs') or [] + for m in container_mounts: + if m.is_tmpfs: + self.options['tmpfs'].append(m.target) + else: + override_options['binds'].append(m.legacy_repr()) + container_options['volumes'][m.target] = {} secret_volumes = self.get_secret_volumes() if secret_volumes: diff --git a/tests/integration/service_test.py b/tests/integration/service_test.py index 7238aa69f..01be48005 100644 --- a/tests/integration/service_test.py +++ b/tests/integration/service_test.py @@ -346,6 +346,21 @@ class ServiceTest(DockerClientTestCase): assert mount assert mount['Name'] == volume_name + @v3_only() + def test_create_container_with_legacy_tmpfs_mount(self): + # Ensure tmpfs mounts are converted to tmpfs entries if API version < 1.30 + # Needed to support long syntax in the 3.2 format + client = docker_client({}, version='1.25') + container_path = '/container-tmpfs' + service = Service('db', client=client, volumes=[ + MountSpec(type='tmpfs', target=container_path) + ], image='busybox:latest', command=['top'], project='composetest') + container = service.create_container() + service.start_container(container) + mount = container.get_mount(container_path) + assert mount is None + assert container_path in container.get('HostConfig.Tmpfs') + def test_create_container_with_healthcheck_config(self): one_second = parse_nanoseconds_int('1s') healthcheck = {