mirror of https://github.com/docker/compose.git
Merge pull request #4324 from shin-/4321-v3-depends-on
Provide valid serialization of depends_on when format is not 2.1
This commit is contained in:
commit
5ade097d74
|
@ -56,9 +56,16 @@ def denormalize_service_dict(service_dict, version):
|
||||||
service_dict = service_dict.copy()
|
service_dict = service_dict.copy()
|
||||||
|
|
||||||
if 'restart' in service_dict:
|
if 'restart' in service_dict:
|
||||||
service_dict['restart'] = types.serialize_restart_spec(service_dict['restart'])
|
service_dict['restart'] = types.serialize_restart_spec(
|
||||||
|
service_dict['restart']
|
||||||
|
)
|
||||||
|
|
||||||
if version == V1 and 'network_mode' not in service_dict:
|
if version == V1 and 'network_mode' not in service_dict:
|
||||||
service_dict['network_mode'] = 'bridge'
|
service_dict['network_mode'] = 'bridge'
|
||||||
|
|
||||||
|
if 'depends_on' in service_dict and version != V2_1:
|
||||||
|
service_dict['depends_on'] = sorted([
|
||||||
|
svc for svc in service_dict['depends_on'].keys()
|
||||||
|
])
|
||||||
|
|
||||||
return service_dict
|
return service_dict
|
||||||
|
|
|
@ -22,6 +22,7 @@ from compose.config.config import V3_0
|
||||||
from compose.config.environment import Environment
|
from compose.config.environment import Environment
|
||||||
from compose.config.errors import ConfigurationError
|
from compose.config.errors import ConfigurationError
|
||||||
from compose.config.errors import VERSION_EXPLANATION
|
from compose.config.errors import VERSION_EXPLANATION
|
||||||
|
from compose.config.serialize import denormalize_service_dict
|
||||||
from compose.config.types import VolumeSpec
|
from compose.config.types import VolumeSpec
|
||||||
from compose.const import IS_WINDOWS_PLATFORM
|
from compose.const import IS_WINDOWS_PLATFORM
|
||||||
from compose.utils import nanoseconds_from_time_seconds
|
from compose.utils import nanoseconds_from_time_seconds
|
||||||
|
@ -3269,3 +3270,33 @@ def get_config_filename_for_files(filenames, subdir=None):
|
||||||
return os.path.basename(filename)
|
return os.path.basename(filename)
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(project_dir)
|
shutil.rmtree(project_dir)
|
||||||
|
|
||||||
|
|
||||||
|
class SerializeTest(unittest.TestCase):
|
||||||
|
def test_denormalize_depends_on_v3(self):
|
||||||
|
service_dict = {
|
||||||
|
'image': 'busybox',
|
||||||
|
'command': 'true',
|
||||||
|
'depends_on': {
|
||||||
|
'service2': {'condition': 'service_started'},
|
||||||
|
'service3': {'condition': 'service_started'},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert denormalize_service_dict(service_dict, V3_0) == {
|
||||||
|
'image': 'busybox',
|
||||||
|
'command': 'true',
|
||||||
|
'depends_on': ['service2', 'service3']
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_denormalize_depends_on_v2_1(self):
|
||||||
|
service_dict = {
|
||||||
|
'image': 'busybox',
|
||||||
|
'command': 'true',
|
||||||
|
'depends_on': {
|
||||||
|
'service2': {'condition': 'service_started'},
|
||||||
|
'service3': {'condition': 'service_started'},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert denormalize_service_dict(service_dict, V2_1) == service_dict
|
||||||
|
|
Loading…
Reference in New Issue