Skip to content

Commit

Permalink
Modified options dict leads to a mismatched config hash for API < 1.30
Browse files Browse the repository at this point in the history
Signed-off-by: Joffrey F <joffrey@docker.com>
  • Loading branch information
shin- committed Feb 7, 2018
1 parent ea64baa commit 84f7bef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compose/service.py
Expand Up @@ -849,10 +849,10 @@ def _build_container_volume_options(self, previous_container, container_options,
override_options['mounts'] = [build_mount(v) for v in container_mounts] or None
else:
# Workaround for 3.2 format
self.options['tmpfs'] = self.options.get('tmpfs') or []
override_options['tmpfs'] = self.options.get('tmpfs') or []
for m in container_mounts:
if m.is_tmpfs:
self.options['tmpfs'].append(m.target)
override_options['tmpfs'].append(m.target)
else:
override_options['binds'].append(m.legacy_repr())
container_options['volumes'][m.target] = {}
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/service_test.py
Expand Up @@ -13,6 +13,7 @@
from compose.config.types import ServiceSecret
from compose.config.types import VolumeFromSpec
from compose.config.types import VolumeSpec
from compose.const import API_VERSIONS
from compose.const import LABEL_CONFIG_HASH
from compose.const import LABEL_ONE_OFF
from compose.const import LABEL_PROJECT
Expand Down Expand Up @@ -601,6 +602,25 @@ def test_config_dict_with_network_mode_from_container(self):
}
assert config_dict == expected

def test_config_hash_matches_label(self):
self.mock_client.inspect_image.return_value = {'Id': 'abcd'}
service = Service(
'foo',
image='example.com/foo',
client=self.mock_client,
network_mode=NetworkMode('bridge'),
networks={'bridge': {}},
links=[(Service('one', client=self.mock_client), 'one')],
volumes_from=[VolumeFromSpec(Service('two', client=self.mock_client), 'rw', 'service')]
)
config_hash = service.config_hash

for api_version in set(API_VERSIONS.values()):
self.mock_client.api_version = api_version
assert service._get_container_create_options({}, 1)['labels'][LABEL_CONFIG_HASH] == (
config_hash
)

def test_remove_image_none(self):
web = Service('web', image='example', client=self.mock_client)
assert not web.remove_image(ImageType.none)
Expand Down

0 comments on commit 84f7bef

Please sign in to comment.