Merge extra_hosts instead of overwrite

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-08-31 15:37:33 -07:00 committed by Joffrey F
parent 36e5985b01
commit fc426e273d
2 changed files with 19 additions and 3 deletions

View File

@ -717,9 +717,6 @@ def process_service(service_config):
if 'labels' in service_dict:
service_dict['labels'] = parse_labels(service_dict['labels'])
if 'extra_hosts' in service_dict:
service_dict['extra_hosts'] = parse_extra_hosts(service_dict['extra_hosts'])
if 'sysctls' in service_dict:
service_dict['sysctls'] = build_string_dict(parse_sysctls(service_dict['sysctls']))
@ -947,6 +944,7 @@ def merge_service_dicts(base, override, version):
md.merge_sequence('secrets', types.ServiceSecret.parse)
md.merge_sequence('configs', types.ServiceConfig.parse)
md.merge_mapping('deploy', parse_deploy)
md.merge_mapping('extra_hosts', parse_extra_hosts)
for field in ['volumes', 'devices']:
md.merge_field(field, merge_path_mappings)

View File

@ -2209,6 +2209,24 @@ class ConfigTest(unittest.TestCase):
}
}
def test_merge_extra_hosts(self):
base = {
'image': 'bar',
'extra_hosts': {
'foo': '1.2.3.4',
}
}
override = {
'extra_hosts': ['bar:5.6.7.8', 'foo:127.0.0.1']
}
actual = config.merge_service_dicts(base, override, V2_0)
assert actual['extra_hosts'] == {
'foo': '127.0.0.1',
'bar': '5.6.7.8',
}
def test_merge_healthcheck_config(self):
base = {
'image': 'bar',