Skip to content

Commit

Permalink
Merge pull request docker#5558 from docker/5554-tmpfs-mount-3.2
Browse files Browse the repository at this point in the history
Support legacy tmpfs mounts
  • Loading branch information
shin- authored Jan 11, 2018
2 parents ac34a83 + 397aa20 commit b2d4d9f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compose/config/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ def repr(self):
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
Expand Down
10 changes: 8 additions & 2 deletions compose/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,14 @@ def _build_container_volume_options(self, previous_container, container_options,
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:
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,21 @@ def test_create_container_with_legacy_mount(self):
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 = {
Expand Down

0 comments on commit b2d4d9f

Please sign in to comment.