mirror of
https://github.com/docker/compose.git
synced 2025-07-22 13:14:29 +02:00
Fix ServiceExtendsResolver same-file detection
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
0c4fc93895
commit
3ea8a20cfa
@ -571,7 +571,7 @@ class ServiceExtendsResolver(object):
|
|||||||
config_path = self.get_extended_config_path(extends)
|
config_path = self.get_extended_config_path(extends)
|
||||||
service_name = extends['service']
|
service_name = extends['service']
|
||||||
|
|
||||||
if config_path == self.service_config.filename:
|
if config_path == self.config_file.filename:
|
||||||
try:
|
try:
|
||||||
service_config = self.config_file.get_service(service_name)
|
service_config = self.config_file.get_service(service_name)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -702,6 +702,42 @@ class ConfigTest(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
self.assertEqual(service_sort(service_dicts), service_sort(expected))
|
self.assertEqual(service_sort(service_dicts), service_sort(expected))
|
||||||
|
|
||||||
|
def test_load_mixed_extends_resolution(self):
|
||||||
|
main_file = config.ConfigFile(
|
||||||
|
'main.yml', {
|
||||||
|
'version': '2.2',
|
||||||
|
'services': {
|
||||||
|
'prodweb': {
|
||||||
|
'extends': {
|
||||||
|
'service': 'web',
|
||||||
|
'file': 'base.yml'
|
||||||
|
},
|
||||||
|
'environment': {'PROD': 'true'},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
tmpdir = pytest.ensuretemp('config_test')
|
||||||
|
self.addCleanup(tmpdir.remove)
|
||||||
|
tmpdir.join('base.yml').write("""
|
||||||
|
version: '2.2'
|
||||||
|
services:
|
||||||
|
base:
|
||||||
|
image: base
|
||||||
|
web:
|
||||||
|
extends: base
|
||||||
|
""")
|
||||||
|
|
||||||
|
details = config.ConfigDetails('.', [main_file])
|
||||||
|
with tmpdir.as_cwd():
|
||||||
|
service_dicts = config.load(details).services
|
||||||
|
assert service_dicts[0] == {
|
||||||
|
'name': 'prodweb',
|
||||||
|
'image': 'base',
|
||||||
|
'environment': {'PROD': 'true'},
|
||||||
|
}
|
||||||
|
|
||||||
def test_load_with_multiple_files_and_invalid_override(self):
|
def test_load_with_multiple_files_and_invalid_override(self):
|
||||||
base_file = config.ConfigFile(
|
base_file = config.ConfigFile(
|
||||||
'base.yaml',
|
'base.yaml',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user