Fix output of 'config' for v1 files
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
8a9ab69a1c
commit
a2ded237e4
3 changed files with 47 additions and 2 deletions
|
|
@ -5,6 +5,8 @@ import six
|
|||
import yaml
|
||||
|
||||
from compose.config import types
|
||||
from compose.config.config import V1
|
||||
from compose.config.config import V2_0
|
||||
|
||||
|
||||
def serialize_config_type(dumper, data):
|
||||
|
|
@ -17,12 +19,20 @@ yaml.SafeDumper.add_representer(types.VolumeSpec, serialize_config_type)
|
|||
|
||||
|
||||
def serialize_config(config):
|
||||
services = {service.pop('name'): service for service in config.services}
|
||||
|
||||
if config.version == V1:
|
||||
for service_dict in services.values():
|
||||
if 'network_mode' not in service_dict:
|
||||
service_dict['network_mode'] = 'bridge'
|
||||
|
||||
output = {
|
||||
'version': config.version,
|
||||
'services': {service.pop('name'): service for service in config.services},
|
||||
'version': V2_0,
|
||||
'services': services,
|
||||
'networks': config.networks,
|
||||
'volumes': config.volumes,
|
||||
}
|
||||
|
||||
return yaml.safe_dump(
|
||||
output,
|
||||
default_flow_style=False,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue