Merge pull request #2878 from dnephin/merge_build_args

Merge build.args when merging services
This commit is contained in:
Aanand Prasad 2016-02-11 17:41:41 +00:00
commit 23ab2c7e44
2 changed files with 45 additions and 17 deletions

View File

@ -714,29 +714,24 @@ def merge_service_dicts(base, override, version):
if version == V1:
legacy_v1_merge_image_or_build(md, base, override)
else:
merge_build(md, base, override)
elif md.needs_merge('build'):
md['build'] = merge_build(md, base, override)
return dict(md)
def merge_build(output, base, override):
build = {}
def to_dict(service):
build_config = service.get('build', {})
if isinstance(build_config, six.string_types):
return {'context': build_config}
return build_config
if 'build' in base:
if isinstance(base['build'], six.string_types):
build['context'] = base['build']
else:
build.update(base['build'])
if 'build' in override:
if isinstance(override['build'], six.string_types):
build['context'] = override['build']
else:
build.update(override['build'])
if build:
output['build'] = build
md = MergeDict(to_dict(base), to_dict(override))
md.merge_scalar('context')
md.merge_scalar('dockerfile')
md.merge_mapping('args', parse_build_arguments)
return dict(md)
def legacy_v1_merge_image_or_build(output, base, override):

View File

@ -1079,6 +1079,39 @@ class ConfigTest(unittest.TestCase):
'extends': {'service': 'foo'}
}
def test_merge_build_args(self):
base = {
'build': {
'context': '.',
'args': {
'ONE': '1',
'TWO': '2',
},
}
}
override = {
'build': {
'args': {
'TWO': 'dos',
'THREE': '3',
},
}
}
actual = config.merge_service_dicts(
base,
override,
DEFAULT_VERSION)
assert actual == {
'build': {
'context': '.',
'args': {
'ONE': '1',
'TWO': 'dos',
'THREE': '3',
},
}
}
def test_external_volume_config(self):
config_details = build_config_details({
'version': '2',