mirror of https://github.com/docker/docs.git
Allow to extend service using shorthand notation. Closes #1989
Signed-off-by: Karol Duleba <mr.fuxi@gmail.com>
This commit is contained in:
parent
03ae2462d4
commit
91b227d133
|
@ -275,15 +275,19 @@ class ServiceLoader(object):
|
||||||
self.service_dict['environment'] = env
|
self.service_dict['environment'] = env
|
||||||
|
|
||||||
def validate_and_construct_extends(self):
|
def validate_and_construct_extends(self):
|
||||||
|
extends = self.service_dict['extends']
|
||||||
|
if not isinstance(extends, dict):
|
||||||
|
extends = {'service': extends}
|
||||||
|
|
||||||
validate_extends_file_path(
|
validate_extends_file_path(
|
||||||
self.service_name,
|
self.service_name,
|
||||||
self.service_dict['extends'],
|
extends,
|
||||||
self.filename
|
self.filename
|
||||||
)
|
)
|
||||||
self.extended_config_path = self.get_extended_config_path(
|
self.extended_config_path = self.get_extended_config_path(
|
||||||
self.service_dict['extends']
|
extends
|
||||||
)
|
)
|
||||||
self.extended_service_name = self.service_dict['extends']['service']
|
self.extended_service_name = extends['service']
|
||||||
|
|
||||||
full_extended_config = pre_process_config(
|
full_extended_config = pre_process_config(
|
||||||
load_yaml(self.extended_config_path)
|
load_yaml(self.extended_config_path)
|
||||||
|
|
|
@ -57,6 +57,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"extends": {
|
"extends": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -65,6 +70,8 @@
|
||||||
},
|
},
|
||||||
"required": ["service"],
|
"required": ["service"],
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
"extra_hosts": {"$ref": "#/definitions/list_or_dict"},
|
"extra_hosts": {"$ref": "#/definitions/list_or_dict"},
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
base:
|
||||||
|
image: busybox
|
||||||
|
environment:
|
||||||
|
- "BAR=1"
|
||||||
|
|
||||||
|
verbose:
|
||||||
|
extends:
|
||||||
|
service: base
|
||||||
|
environment:
|
||||||
|
- "FOO=1"
|
||||||
|
|
||||||
|
shorthand:
|
||||||
|
extends: base
|
||||||
|
environment:
|
||||||
|
- "FOO=2"
|
|
@ -1115,6 +1115,26 @@ class ExtendsTest(unittest.TestCase):
|
||||||
dicts = load_from_filename('tests/fixtures/extends/valid-common-config.yml')
|
dicts = load_from_filename('tests/fixtures/extends/valid-common-config.yml')
|
||||||
self.assertEqual(dicts[0]['environment'], {'FOO': '1'})
|
self.assertEqual(dicts[0]['environment'], {'FOO': '1'})
|
||||||
|
|
||||||
|
def test_extended_service_with_verbose_and_shorthand_way(self):
|
||||||
|
services = load_from_filename('tests/fixtures/extends/verbose-and-shorthand.yml')
|
||||||
|
self.assertEqual(service_sort(services), service_sort([
|
||||||
|
{
|
||||||
|
'name': 'base',
|
||||||
|
'image': 'busybox',
|
||||||
|
'environment': {'BAR': '1'},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'verbose',
|
||||||
|
'image': 'busybox',
|
||||||
|
'environment': {'BAR': '1', 'FOO': '1'},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'shorthand',
|
||||||
|
'image': 'busybox',
|
||||||
|
'environment': {'BAR': '1', 'FOO': '2'},
|
||||||
|
},
|
||||||
|
]))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason='paths use slash')
|
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason='paths use slash')
|
||||||
class ExpandPathTest(unittest.TestCase):
|
class ExpandPathTest(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue