mirror of https://github.com/docker/compose.git
Pick the first container
Rather than inefficiently looping through all the containers that a service has and overriding each volumes_from value, pick the first one and return that. Signed-off-by: Mazz Mosley <mazz@houseofmnowster.com>
This commit is contained in:
parent
0ff84a78c6
commit
f9028703f4
|
@ -994,8 +994,9 @@ def build_volume_from(volume_from_spec):
|
||||||
containers = volume_from_spec.source.containers(stopped=True)
|
containers = volume_from_spec.source.containers(stopped=True)
|
||||||
if not containers:
|
if not containers:
|
||||||
return ["{}:{}".format(volume_from_spec.source.create_container().id, volume_from_spec.mode)]
|
return ["{}:{}".format(volume_from_spec.source.create_container().id, volume_from_spec.mode)]
|
||||||
else:
|
|
||||||
return ["{}:{}".format(container.id, volume_from_spec.mode) for container in containers]
|
container = containers[0]
|
||||||
|
return ["{}:{}".format(container.id, volume_from_spec.mode)]
|
||||||
elif isinstance(volume_from_spec.source, Container):
|
elif isinstance(volume_from_spec.source, Container):
|
||||||
return ["{}:{}".format(volume_from_spec.source.id, volume_from_spec.mode)]
|
return ["{}:{}".format(volume_from_spec.source.id, volume_from_spec.mode)]
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ class ProjectTest(unittest.TestCase):
|
||||||
'volumes_from': ['vol']
|
'volumes_from': ['vol']
|
||||||
}
|
}
|
||||||
], None)
|
], None)
|
||||||
self.assertEqual(project.get_service('test')._get_volumes_from(), [cid + ':rw' for cid in container_ids])
|
self.assertEqual(project.get_service('test')._get_volumes_from(), [container_ids[0] + ':rw'])
|
||||||
|
|
||||||
def test_net_unset(self):
|
def test_net_unset(self):
|
||||||
project = Project.from_dicts('test', [
|
project = Project.from_dicts('test', [
|
||||||
|
|
|
@ -98,7 +98,7 @@ class ServiceTest(unittest.TestCase):
|
||||||
]
|
]
|
||||||
service = Service('test', volumes_from=[VolumeFromSpec(from_service, 'rw')], image='foo')
|
service = Service('test', volumes_from=[VolumeFromSpec(from_service, 'rw')], image='foo')
|
||||||
|
|
||||||
self.assertEqual(service._get_volumes_from(), [cid + ":rw" for cid in container_ids])
|
self.assertEqual(service._get_volumes_from(), [container_ids[0] + ":rw"])
|
||||||
|
|
||||||
def test_get_volumes_from_service_container_exists_with_flags(self):
|
def test_get_volumes_from_service_container_exists_with_flags(self):
|
||||||
for mode in ['ro', 'rw', 'z', 'rw,z', 'z,rw']:
|
for mode in ['ro', 'rw', 'z', 'rw,z', 'z,rw']:
|
||||||
|
@ -110,7 +110,7 @@ class ServiceTest(unittest.TestCase):
|
||||||
]
|
]
|
||||||
service = Service('test', volumes_from=[VolumeFromSpec(from_service, mode)], image='foo')
|
service = Service('test', volumes_from=[VolumeFromSpec(from_service, mode)], image='foo')
|
||||||
|
|
||||||
self.assertEqual(service._get_volumes_from(), container_ids)
|
self.assertEqual(service._get_volumes_from(), [container_ids[0]])
|
||||||
|
|
||||||
def test_get_volumes_from_service_no_container(self):
|
def test_get_volumes_from_service_no_container(self):
|
||||||
container_id = 'abababab'
|
container_id = 'abababab'
|
||||||
|
|
Loading…
Reference in New Issue