mirror of
https://github.com/docker/compose.git
synced 2025-07-06 21:34:25 +02:00
Add "secrets" section to docker-compose config output when applicable
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
dd294ce9cc
commit
23b873c2ce
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
VERSION_EXPLANATION = (
|
VERSION_EXPLANATION = (
|
||||||
'You might be seeing this error because you\'re using the wrong Compose file version. '
|
'You might be seeing this error because you\'re using the wrong Compose file version. '
|
||||||
'Either specify a supported version ("2.0", "2.1", "3.0") and place your '
|
'Either specify a supported version ("2.0", "2.1", "3.0", "3.1") and place your '
|
||||||
'service definitions under the `services` key, or omit the `version` key '
|
'service definitions under the `services` key, or omit the `version` key '
|
||||||
'and place your service definitions at the root of the file to use '
|
'and place your service definitions at the root of the file to use '
|
||||||
'version 1.\nFor more on the Compose file format versions, see '
|
'version 1.\nFor more on the Compose file format versions, see '
|
||||||
|
@ -26,34 +26,28 @@ yaml.SafeDumper.add_representer(types.ServicePort, serialize_dict_type)
|
|||||||
|
|
||||||
|
|
||||||
def denormalize_config(config):
|
def denormalize_config(config):
|
||||||
|
result = {'version': V2_1 if config.version == V1 else config.version}
|
||||||
denormalized_services = [
|
denormalized_services = [
|
||||||
denormalize_service_dict(service_dict, config.version)
|
denormalize_service_dict(service_dict, config.version)
|
||||||
for service_dict in config.services
|
for service_dict in config.services
|
||||||
]
|
]
|
||||||
services = {
|
result['services'] = {
|
||||||
service_dict.pop('name'): service_dict
|
service_dict.pop('name'): service_dict
|
||||||
for service_dict in denormalized_services
|
for service_dict in denormalized_services
|
||||||
}
|
}
|
||||||
networks = config.networks.copy()
|
result['networks'] = config.networks.copy()
|
||||||
for net_name, net_conf in networks.items():
|
for net_name, net_conf in result['networks'].items():
|
||||||
if 'external_name' in net_conf:
|
if 'external_name' in net_conf:
|
||||||
del net_conf['external_name']
|
del net_conf['external_name']
|
||||||
|
|
||||||
volumes = config.volumes.copy()
|
result['volumes'] = config.volumes.copy()
|
||||||
for vol_name, vol_conf in volumes.items():
|
for vol_name, vol_conf in result['volumes'].items():
|
||||||
if 'external_name' in vol_conf:
|
if 'external_name' in vol_conf:
|
||||||
del vol_conf['external_name']
|
del vol_conf['external_name']
|
||||||
|
|
||||||
version = config.version
|
if config.version in (V3_1,):
|
||||||
if version == V1:
|
result['secrets'] = config.secrets
|
||||||
version = V2_1
|
return result
|
||||||
|
|
||||||
return {
|
|
||||||
'version': version,
|
|
||||||
'services': services,
|
|
||||||
'networks': networks,
|
|
||||||
'volumes': volumes,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def serialize_config(config):
|
def serialize_config(config):
|
||||||
|
@ -3650,11 +3650,17 @@ class SerializeTest(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
secrets_dict = {
|
||||||
|
'one': {'file': '/one.txt'},
|
||||||
|
'source': {'file': '/source.pem'}
|
||||||
|
}
|
||||||
config_dict = config.load(build_config_details({
|
config_dict = config.load(build_config_details({
|
||||||
'version': '3.1',
|
'version': '3.1',
|
||||||
'services': {'web': service_dict}
|
'services': {'web': service_dict},
|
||||||
|
'secrets': secrets_dict
|
||||||
}))
|
}))
|
||||||
|
|
||||||
serialized_config = yaml.load(serialize_config(config_dict))
|
serialized_config = yaml.load(serialize_config(config_dict))
|
||||||
serialized_service = serialized_config['services']['web']
|
serialized_service = serialized_config['services']['web']
|
||||||
assert secret_sort(serialized_service['secrets']) == secret_sort(service_dict['secrets'])
|
assert secret_sort(serialized_service['secrets']) == secret_sort(service_dict['secrets'])
|
||||||
|
assert serialized_config['secrets'] == secrets_dict
|
||||||
|
Loading…
x
Reference in New Issue
Block a user