mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Fix override volume merging + add acceptance test
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
4796e04cae
commit
ec4ba7752f
@ -736,8 +736,7 @@ class Service(object):
|
|||||||
container_options = dict(
|
container_options = dict(
|
||||||
(k, self.options[k])
|
(k, self.options[k])
|
||||||
for k in DOCKER_CONFIG_KEYS if k in self.options)
|
for k in DOCKER_CONFIG_KEYS if k in self.options)
|
||||||
override_options['volumes'] = (container_options.get('volumes', []) +
|
override_volumes = override_options.pop('volumes', [])
|
||||||
override_options.get('volumes', []))
|
|
||||||
container_options.update(override_options)
|
container_options.update(override_options)
|
||||||
|
|
||||||
if not container_options.get('name'):
|
if not container_options.get('name'):
|
||||||
@ -761,6 +760,11 @@ class Service(object):
|
|||||||
formatted_ports(container_options.get('ports', [])),
|
formatted_ports(container_options.get('ports', [])),
|
||||||
self.options)
|
self.options)
|
||||||
|
|
||||||
|
if 'volumes' in container_options or override_volumes:
|
||||||
|
container_options['volumes'] = list(set(
|
||||||
|
container_options.get('volumes', []) + override_volumes
|
||||||
|
))
|
||||||
|
|
||||||
container_options['environment'] = merge_environment(
|
container_options['environment'] = merge_environment(
|
||||||
self.options.get('environment'),
|
self.options.get('environment'),
|
||||||
override_options.get('environment'))
|
override_options.get('environment'))
|
||||||
|
@ -609,8 +609,13 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
'simple',
|
'simple',
|
||||||
'test', '-f', '/data/example.txt'
|
'test', '-f', '/data/example.txt'
|
||||||
], returncode=0)
|
], returncode=0)
|
||||||
# FIXME: does not work with Python 3
|
|
||||||
# assert cmd_result.stdout.strip() == 'FILE_CONTENT'
|
service = self.project.get_service('simple')
|
||||||
|
container_data = service.containers(one_off=OneOffFilter.only, stopped=True)[0]
|
||||||
|
mount = container_data.get('Mounts')[0]
|
||||||
|
assert mount['Source'] == volume_path
|
||||||
|
assert mount['Destination'] == '/data'
|
||||||
|
assert mount['Type'] == 'bind'
|
||||||
|
|
||||||
def test_run_one_off_with_multiple_volumes(self):
|
def test_run_one_off_with_multiple_volumes(self):
|
||||||
self.base_dir = 'tests/fixtures/simple-composefile-volume-ready'
|
self.base_dir = 'tests/fixtures/simple-composefile-volume-ready'
|
||||||
@ -624,8 +629,6 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
'simple',
|
'simple',
|
||||||
'test', '-f', '/data/example.txt'
|
'test', '-f', '/data/example.txt'
|
||||||
], returncode=0)
|
], returncode=0)
|
||||||
# FIXME: does not work with Python 3
|
|
||||||
# assert cmd_result.stdout.strip() == 'FILE_CONTENT'
|
|
||||||
|
|
||||||
self.dispatch([
|
self.dispatch([
|
||||||
'run',
|
'run',
|
||||||
@ -634,8 +637,30 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
'simple',
|
'simple',
|
||||||
'test', '-f' '/data1/example.txt'
|
'test', '-f' '/data1/example.txt'
|
||||||
], returncode=0)
|
], returncode=0)
|
||||||
# FIXME: does not work with Python 3
|
|
||||||
# assert cmd_result.stdout.strip() == 'FILE_CONTENT'
|
def test_run_one_off_with_volume_merge(self):
|
||||||
|
self.base_dir = 'tests/fixtures/simple-composefile-volume-ready'
|
||||||
|
volume_path = os.path.abspath(os.path.join(os.getcwd(), self.base_dir, 'files'))
|
||||||
|
create_host_file(self.client, os.path.join(volume_path, 'example.txt'))
|
||||||
|
|
||||||
|
self.dispatch([
|
||||||
|
'-f', 'docker-compose.merge.yml',
|
||||||
|
'run',
|
||||||
|
'-v', '{}:/data'.format(volume_path),
|
||||||
|
'simple',
|
||||||
|
'test', '-f', '/data/example.txt'
|
||||||
|
], returncode=0)
|
||||||
|
|
||||||
|
service = self.project.get_service('simple')
|
||||||
|
container_data = service.containers(one_off=OneOffFilter.only, stopped=True)[0]
|
||||||
|
mounts = container_data.get('Mounts')
|
||||||
|
assert len(mounts) == 2
|
||||||
|
config_mount = [m for m in mounts if m['Destination'] == '/data1'][0]
|
||||||
|
override_mount = [m for m in mounts if m['Destination'] == '/data'][0]
|
||||||
|
|
||||||
|
assert config_mount['Type'] == 'volume'
|
||||||
|
assert override_mount['Source'] == volume_path
|
||||||
|
assert override_mount['Type'] == 'bind'
|
||||||
|
|
||||||
def test_create_with_force_recreate_and_no_recreate(self):
|
def test_create_with_force_recreate_and_no_recreate(self):
|
||||||
self.dispatch(
|
self.dispatch(
|
||||||
|
9
tests/fixtures/simple-composefile-volume-ready/docker-compose.merge.yml
vendored
Normal file
9
tests/fixtures/simple-composefile-volume-ready/docker-compose.merge.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
version: '2.2'
|
||||||
|
services:
|
||||||
|
simple:
|
||||||
|
image: busybox:latest
|
||||||
|
volumes:
|
||||||
|
- datastore:/data1
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
datastore:
|
Loading…
x
Reference in New Issue
Block a user