mirror of https://github.com/docker/compose.git
Ulimits are now merged into extended services
Signed-off-by: Dimitar Bonev <dimitar.bonev@gmail.com>
This commit is contained in:
parent
0c626e63bc
commit
2f07e2ac36
|
@ -547,8 +547,15 @@ def merge_service_dicts(base, override, version):
|
|||
base.get(field, default),
|
||||
override.get(field, default))
|
||||
|
||||
merge_field('environment', merge_environment)
|
||||
merge_field('labels', merge_labels)
|
||||
def merge_mapping(mapping, parse_func):
|
||||
if mapping in base or mapping in override:
|
||||
merged = parse_func(base.get(mapping, None))
|
||||
merged.update(parse_func(override.get(mapping, None)))
|
||||
d[mapping] = merged
|
||||
|
||||
merge_mapping('environment', parse_environment)
|
||||
merge_mapping('labels', parse_labels)
|
||||
merge_mapping('ulimits', parse_ulimits)
|
||||
|
||||
for field in ['volumes', 'devices']:
|
||||
merge_field(field, merge_path_mappings)
|
||||
|
@ -723,12 +730,6 @@ def join_path_mapping(pair):
|
|||
return ":".join((host, container))
|
||||
|
||||
|
||||
def merge_labels(base, override):
|
||||
labels = parse_labels(base)
|
||||
labels.update(parse_labels(override))
|
||||
return labels
|
||||
|
||||
|
||||
def parse_labels(labels):
|
||||
if not labels:
|
||||
return {}
|
||||
|
@ -747,6 +748,14 @@ def split_label(label):
|
|||
return label, ''
|
||||
|
||||
|
||||
def parse_ulimits(ulimits):
|
||||
if not ulimits:
|
||||
return {}
|
||||
|
||||
if isinstance(ulimits, dict):
|
||||
return dict(ulimits)
|
||||
|
||||
|
||||
def expand_path(working_dir, path):
|
||||
return os.path.abspath(os.path.join(working_dir, os.path.expanduser(path)))
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
web:
|
||||
extends:
|
||||
file: common.yml
|
||||
service: web
|
||||
environment:
|
||||
- FOO=2
|
||||
- BAZ=3
|
||||
labels: ['label=one']
|
||||
ulimits:
|
||||
nproc: 65535
|
||||
memlock:
|
||||
soft: 1024
|
||||
hard: 2048
|
|
@ -1396,6 +1396,24 @@ class ExtendsTest(unittest.TestCase):
|
|||
}
|
||||
]))
|
||||
|
||||
def test_merging_env_labels_ulimits(self):
|
||||
service_dicts = load_from_filename('tests/fixtures/extends/common-env-labels-ulimits.yml')
|
||||
|
||||
self.assertEqual(service_sort(service_dicts), service_sort([
|
||||
{
|
||||
'name': 'web',
|
||||
'image': 'busybox',
|
||||
'command': '/bin/true',
|
||||
'environment': {
|
||||
"FOO": "2",
|
||||
"BAR": "1",
|
||||
"BAZ": "3",
|
||||
},
|
||||
'labels': {'label': 'one'},
|
||||
'ulimits': {'nproc': 65535, 'memlock': {'soft': 1024, 'hard': 2048}}
|
||||
}
|
||||
]))
|
||||
|
||||
def test_nested(self):
|
||||
service_dicts = load_from_filename('tests/fixtures/extends/nested.yml')
|
||||
|
||||
|
|
Loading…
Reference in New Issue