瀏覽代碼

Merge pull request #5558 from docker/5554-tmpfs-mount-3.2

Support legacy tmpfs mounts
Joffrey F 7 年之前
父節點
當前提交
b2d4d9f2bc
共有 3 個文件被更改,包括 27 次插入2 次删除
  1. 4 0
      compose/config/types.py
  2. 8 2
      compose/service.py
  3. 15 0
      tests/integration/service_test.py

+ 4 - 0
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

+ 8 - 2
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:

+ 15 - 0
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 = {