mirror of
https://github.com/docker/compose.git
synced 2025-07-22 05:04:27 +02:00
Fix output of 'config' for v1 files
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
84a3e2fe79
commit
6064d200f9
@ -5,6 +5,8 @@ import six
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from compose.config import types
|
from compose.config import types
|
||||||
|
from compose.config.config import V1
|
||||||
|
from compose.config.config import V2_0
|
||||||
|
|
||||||
|
|
||||||
def serialize_config_type(dumper, data):
|
def serialize_config_type(dumper, data):
|
||||||
@ -17,12 +19,20 @@ yaml.SafeDumper.add_representer(types.VolumeSpec, serialize_config_type)
|
|||||||
|
|
||||||
|
|
||||||
def serialize_config(config):
|
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 = {
|
output = {
|
||||||
'version': config.version,
|
'version': V2_0,
|
||||||
'services': {service.pop('name'): service for service in config.services},
|
'services': services,
|
||||||
'networks': config.networks,
|
'networks': config.networks,
|
||||||
'volumes': config.volumes,
|
'volumes': config.volumes,
|
||||||
}
|
}
|
||||||
|
|
||||||
return yaml.safe_dump(
|
return yaml.safe_dump(
|
||||||
output,
|
output,
|
||||||
default_flow_style=False,
|
default_flow_style=False,
|
||||||
|
@ -190,6 +190,31 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
}
|
}
|
||||||
assert output == expected
|
assert output == expected
|
||||||
|
|
||||||
|
def test_config_v1(self):
|
||||||
|
self.base_dir = 'tests/fixtures/v1-config'
|
||||||
|
result = self.dispatch(['config'])
|
||||||
|
assert yaml.load(result.stdout) == {
|
||||||
|
'version': '2.0',
|
||||||
|
'services': {
|
||||||
|
'net': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'network_mode': 'bridge',
|
||||||
|
},
|
||||||
|
'volume': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'volumes': ['/data:rw'],
|
||||||
|
'network_mode': 'bridge',
|
||||||
|
},
|
||||||
|
'app': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'volumes_from': ['service:volume:rw'],
|
||||||
|
'network_mode': 'service:net',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'networks': {},
|
||||||
|
'volumes': {},
|
||||||
|
}
|
||||||
|
|
||||||
def test_ps(self):
|
def test_ps(self):
|
||||||
self.project.get_service('simple').create_container()
|
self.project.get_service('simple').create_container()
|
||||||
result = self.dispatch(['ps'])
|
result = self.dispatch(['ps'])
|
||||||
|
10
tests/fixtures/v1-config/docker-compose.yml
vendored
Normal file
10
tests/fixtures/v1-config/docker-compose.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
net:
|
||||||
|
image: busybox
|
||||||
|
volume:
|
||||||
|
image: busybox
|
||||||
|
volumes:
|
||||||
|
- /data
|
||||||
|
app:
|
||||||
|
image: busybox
|
||||||
|
net: "container:net"
|
||||||
|
volumes_from: ["volume"]
|
Loading…
x
Reference in New Issue
Block a user