mirror of https://github.com/docker/compose.git
Use VolumeSpec instead of re-parsing the volume string.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
0e19c92e82
commit
ec22d98377
|
@ -911,14 +911,15 @@ def merge_volume_bindings(volumes_option, previous_container):
|
||||||
"""Return a list of volume bindings for a container. Container data volumes
|
"""Return a list of volume bindings for a container. Container data volumes
|
||||||
are replaced by those from the previous container.
|
are replaced by those from the previous container.
|
||||||
"""
|
"""
|
||||||
|
volumes = [parse_volume_spec(volume) for volume in volumes_option or []]
|
||||||
volume_bindings = dict(
|
volume_bindings = dict(
|
||||||
build_volume_binding(parse_volume_spec(volume))
|
build_volume_binding(volume)
|
||||||
for volume in volumes_option or []
|
for volume in volumes
|
||||||
if ':' in volume)
|
if volume.external)
|
||||||
|
|
||||||
if previous_container:
|
if previous_container:
|
||||||
volume_bindings.update(
|
volume_bindings.update(
|
||||||
get_container_data_volumes(previous_container, volumes_option))
|
get_container_data_volumes(previous_container, volumes))
|
||||||
|
|
||||||
return list(volume_bindings.values())
|
return list(volume_bindings.values())
|
||||||
|
|
||||||
|
@ -929,12 +930,14 @@ def get_container_data_volumes(container, volumes_option):
|
||||||
"""
|
"""
|
||||||
volumes = []
|
volumes = []
|
||||||
|
|
||||||
volumes_option = volumes_option or []
|
|
||||||
container_volumes = container.get('Volumes') or {}
|
container_volumes = container.get('Volumes') or {}
|
||||||
image_volumes = container.image_config['ContainerConfig'].get('Volumes') or {}
|
image_volumes = [
|
||||||
|
parse_volume_spec(volume)
|
||||||
|
for volume in
|
||||||
|
container.image_config['ContainerConfig'].get('Volumes') or {}
|
||||||
|
]
|
||||||
|
|
||||||
for volume in set(volumes_option + list(image_volumes)):
|
for volume in set(volumes_option + image_volumes):
|
||||||
volume = parse_volume_spec(volume)
|
|
||||||
# No need to preserve host volumes
|
# No need to preserve host volumes
|
||||||
if volume.external:
|
if volume.external:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -593,11 +593,11 @@ class ServiceVolumesTest(unittest.TestCase):
|
||||||
self.assertEqual(binding, ('/inside', '/outside:/inside:rw'))
|
self.assertEqual(binding, ('/inside', '/outside:/inside:rw'))
|
||||||
|
|
||||||
def test_get_container_data_volumes(self):
|
def test_get_container_data_volumes(self):
|
||||||
options = [
|
options = [parse_volume_spec(v) for v in [
|
||||||
'/host/volume:/host/volume:ro',
|
'/host/volume:/host/volume:ro',
|
||||||
'/new/volume',
|
'/new/volume',
|
||||||
'/existing/volume',
|
'/existing/volume',
|
||||||
]
|
]]
|
||||||
|
|
||||||
self.mock_client.inspect_image.return_value = {
|
self.mock_client.inspect_image.return_value = {
|
||||||
'ContainerConfig': {
|
'ContainerConfig': {
|
||||||
|
|
Loading…
Reference in New Issue