mirror of
https://github.com/docker/compose.git
synced 2025-07-20 04:04:29 +02:00
Add partial support (docker-compose config and warnings) for v3.3 credential_spec
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
972fe65830
commit
73d7865da8
@ -108,6 +108,7 @@ DOCKER_CONFIG_KEYS = [
|
|||||||
ALLOWED_KEYS = DOCKER_CONFIG_KEYS + [
|
ALLOWED_KEYS = DOCKER_CONFIG_KEYS + [
|
||||||
'build',
|
'build',
|
||||||
'container_name',
|
'container_name',
|
||||||
|
'credential_spec',
|
||||||
'dockerfile',
|
'dockerfile',
|
||||||
'log_driver',
|
'log_driver',
|
||||||
'log_opt',
|
'log_opt',
|
||||||
@ -320,6 +321,27 @@ def find_candidates_in_parent_dirs(filenames, path):
|
|||||||
return (candidates, path)
|
return (candidates, path)
|
||||||
|
|
||||||
|
|
||||||
|
def check_swarm_only_config(service_dicts):
|
||||||
|
warning_template = (
|
||||||
|
"Some services ({services}) use the '{key}' key, which will be ignored. "
|
||||||
|
"Compose does not support '{key}' configuration - use "
|
||||||
|
"`docker stack deploy` to deploy to a swarm."
|
||||||
|
)
|
||||||
|
|
||||||
|
def check_swarm_only_key(service_dicts, key):
|
||||||
|
services = [s for s in service_dicts if s.get(key)]
|
||||||
|
if services:
|
||||||
|
log.warn(
|
||||||
|
warning_template.format(
|
||||||
|
services=", ".join(sorted(s['name'] for s in services)),
|
||||||
|
key=key
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
check_swarm_only_key(service_dicts, 'deploy')
|
||||||
|
check_swarm_only_key(service_dicts, 'credential_spec')
|
||||||
|
|
||||||
|
|
||||||
def load(config_details):
|
def load(config_details):
|
||||||
"""Load the configuration from a working directory and a list of
|
"""Load the configuration from a working directory and a list of
|
||||||
configuration files. Files are loaded in order, and merged on top
|
configuration files. Files are loaded in order, and merged on top
|
||||||
@ -349,13 +371,7 @@ def load(config_details):
|
|||||||
for service_dict in service_dicts:
|
for service_dict in service_dicts:
|
||||||
match_named_volumes(service_dict, volumes)
|
match_named_volumes(service_dict, volumes)
|
||||||
|
|
||||||
services_using_deploy = [s for s in service_dicts if s.get('deploy')]
|
check_swarm_only_config(service_dicts)
|
||||||
if services_using_deploy:
|
|
||||||
log.warn(
|
|
||||||
"Some services ({}) use the 'deploy' key, which will be ignored. "
|
|
||||||
"Compose does not support deploy configuration - use "
|
|
||||||
"`docker stack deploy` to deploy to a swarm."
|
|
||||||
.format(", ".join(sorted(s['name'] for s in services_using_deploy))))
|
|
||||||
|
|
||||||
return Config(main_file.version, service_dicts, volumes, networks, secrets)
|
return Config(main_file.version, service_dicts, volumes, networks, secrets)
|
||||||
|
|
||||||
@ -884,7 +900,7 @@ def merge_service_dicts(base, override, version):
|
|||||||
|
|
||||||
md.merge_mapping('environment', parse_environment)
|
md.merge_mapping('environment', parse_environment)
|
||||||
md.merge_mapping('labels', parse_labels)
|
md.merge_mapping('labels', parse_labels)
|
||||||
md.merge_mapping('ulimits', parse_ulimits)
|
md.merge_mapping('ulimits', parse_flat_dict)
|
||||||
md.merge_mapping('networks', parse_networks)
|
md.merge_mapping('networks', parse_networks)
|
||||||
md.merge_mapping('sysctls', parse_sysctls)
|
md.merge_mapping('sysctls', parse_sysctls)
|
||||||
md.merge_mapping('depends_on', parse_depends_on)
|
md.merge_mapping('depends_on', parse_depends_on)
|
||||||
@ -1018,12 +1034,14 @@ parse_depends_on = functools.partial(
|
|||||||
parse_deploy = functools.partial(parse_dict_or_list, split_kv, 'deploy')
|
parse_deploy = functools.partial(parse_dict_or_list, split_kv, 'deploy')
|
||||||
|
|
||||||
|
|
||||||
def parse_ulimits(ulimits):
|
def parse_flat_dict(d):
|
||||||
if not ulimits:
|
if not d:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
if isinstance(ulimits, dict):
|
if isinstance(d, dict):
|
||||||
return dict(ulimits)
|
return dict(d)
|
||||||
|
|
||||||
|
raise ConfigurationError("Invalid type: expected mapping")
|
||||||
|
|
||||||
|
|
||||||
def resolve_env_var(key, val, environment):
|
def resolve_env_var(key, val, environment):
|
||||||
|
@ -2033,6 +2033,23 @@ class ConfigTest(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def test_merge_credential_spec(self):
|
||||||
|
base = {
|
||||||
|
'image': 'bb',
|
||||||
|
'credential_spec': {
|
||||||
|
'file': '/hello-world',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override = {
|
||||||
|
'credential_spec': {
|
||||||
|
'registry': 'revolution.com',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actual = config.merge_service_dicts(base, override, V3_3)
|
||||||
|
assert actual['credential_spec'] == override['credential_spec']
|
||||||
|
|
||||||
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…
x
Reference in New Issue
Block a user