Skip to content

Commit 84f7bef

Browse files
committed
Modified options dict leads to a mismatched config hash for API < 1.30
Signed-off-by: Joffrey F <[email protected]>
1 parent ea64baa commit 84f7bef

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

compose/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,10 +849,10 @@ def _build_container_volume_options(self, previous_container, container_options,
849849
override_options['mounts'] = [build_mount(v) for v in container_mounts] or None
850850
else:
851851
# Workaround for 3.2 format
852-
self.options['tmpfs'] = self.options.get('tmpfs') or []
852+
override_options['tmpfs'] = self.options.get('tmpfs') or []
853853
for m in container_mounts:
854854
if m.is_tmpfs:
855-
self.options['tmpfs'].append(m.target)
855+
override_options['tmpfs'].append(m.target)
856856
else:
857857
override_options['binds'].append(m.legacy_repr())
858858
container_options['volumes'][m.target] = {}

tests/unit/service_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from compose.config.types import ServiceSecret
1414
from compose.config.types import VolumeFromSpec
1515
from compose.config.types import VolumeSpec
16+
from compose.const import API_VERSIONS
1617
from compose.const import LABEL_CONFIG_HASH
1718
from compose.const import LABEL_ONE_OFF
1819
from compose.const import LABEL_PROJECT
@@ -601,6 +602,25 @@ def test_config_dict_with_network_mode_from_container(self):
601602
}
602603
assert config_dict == expected
603604

605+
def test_config_hash_matches_label(self):
606+
self.mock_client.inspect_image.return_value = {'Id': 'abcd'}
607+
service = Service(
608+
'foo',
609+
image='example.com/foo',
610+
client=self.mock_client,
611+
network_mode=NetworkMode('bridge'),
612+
networks={'bridge': {}},
613+
links=[(Service('one', client=self.mock_client), 'one')],
614+
volumes_from=[VolumeFromSpec(Service('two', client=self.mock_client), 'rw', 'service')]
615+
)
616+
config_hash = service.config_hash
617+
618+
for api_version in set(API_VERSIONS.values()):
619+
self.mock_client.api_version = api_version
620+
assert service._get_container_create_options({}, 1)['labels'][LABEL_CONFIG_HASH] == (
621+
config_hash
622+
)
623+
604624
def test_remove_image_none(self):
605625
web = Service('web', image='example', client=self.mock_client)
606626
assert not web.remove_image(ImageType.none)

0 commit comments

Comments
 (0)