mirror of https://github.com/docker/compose.git
Merge build.args when merging services.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
2ced83e3d9
commit
155efd28fa
|
@ -713,29 +713,24 @@ def merge_service_dicts(base, override, version):
|
||||||
|
|
||||||
if version == V1:
|
if version == V1:
|
||||||
legacy_v1_merge_image_or_build(md, base, override)
|
legacy_v1_merge_image_or_build(md, base, override)
|
||||||
else:
|
elif md.needs_merge('build'):
|
||||||
merge_build(md, base, override)
|
md['build'] = merge_build(md, base, override)
|
||||||
|
|
||||||
return dict(md)
|
return dict(md)
|
||||||
|
|
||||||
|
|
||||||
def merge_build(output, base, override):
|
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:
|
md = MergeDict(to_dict(base), to_dict(override))
|
||||||
if isinstance(base['build'], six.string_types):
|
md.merge_scalar('context')
|
||||||
build['context'] = base['build']
|
md.merge_scalar('dockerfile')
|
||||||
else:
|
md.merge_mapping('args', parse_build_arguments)
|
||||||
build.update(base['build'])
|
return dict(md)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def legacy_v1_merge_image_or_build(output, base, override):
|
def legacy_v1_merge_image_or_build(output, base, override):
|
||||||
|
|
|
@ -1079,6 +1079,39 @@ class ConfigTest(unittest.TestCase):
|
||||||
'extends': {'service': 'foo'}
|
'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):
|
def test_external_volume_config(self):
|
||||||
config_details = build_config_details({
|
config_details = build_config_details({
|
||||||
'version': '2',
|
'version': '2',
|
||||||
|
|
Loading…
Reference in New Issue