From 9d7202d12256d8672b0ddfa6840877e551323f08 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 5 Oct 2018 14:52:56 +0600 Subject: [PATCH] Squashed commit of the following: commit d3fbd3d630099dc0d34cb1a93b0a664f633a1c25 Author: zasca Date: Wed Oct 3 11:27:43 2018 +0600 Fix typo in function name, path separator updated commit bc3f03cd9a7702b3f2d96b18380d75e10f18def0 Author: zasca Date: Tue Oct 2 11:12:28 2018 +0600 Fix endswith arg in the test commit 602d2977b4e881850c99c7555bc284690a802815 Author: zasca Date: Mon Oct 1 12:24:17 2018 +0600 Update test commit 6cd7a4a2c411ddf9b8e7d91194c60fb2238db8d7 Author: zasca Date: Fri Sep 28 11:13:36 2018 +0600 Fix last test commit 0d37343433caceec18ea15babf924b5975b83c80 Author: zasca Date: Fri Sep 28 10:58:57 2018 +0600 Unit test added commit fc086e544677dd33bad798c773cb92600aaefc51 Author: zasca Date: Thu Sep 27 20:28:03 2018 +0600 Improved expanding source paths of volumes defined with long syntax when paths starts with '~' Signed-off-by: Alexander --- compose/config/config.py | 2 +- tests/unit/config/config_test.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/compose/config/config.py b/compose/config/config.py index 7abab2546..fb2c742f4 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -1281,7 +1281,7 @@ def resolve_volume_paths(working_dir, service_dict): def resolve_volume_path(working_dir, volume): if isinstance(volume, dict): - if volume.get('source', '').startswith('.') and volume['type'] == 'bind': + if volume.get('source', '').startswith(('.', '~')) and volume['type'] == 'bind': volume['source'] = expand_path(working_dir, volume['source']) return volume diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index 1d42c10d5..8f98a7515 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -1322,6 +1322,29 @@ class ConfigTest(unittest.TestCase): assert mount.type == 'bind' assert mount.source == expected_source + def test_load_bind_mount_relative_path_with_tilde(self): + base_file = config.ConfigFile( + 'base.yaml', { + 'version': '3.4', + 'services': { + 'web': { + 'image': 'busybox:latest', + 'volumes': [ + {'type': 'bind', 'source': '~/web', 'target': '/web'}, + ], + }, + }, + }, + ) + + details = config.ConfigDetails('.', [base_file]) + config_data = config.load(details) + mount = config_data.services[0].get('volumes')[0] + assert mount.target == '/web' + assert mount.type == 'bind' + assert (not mount.source.startswith('~') + and mount.source.endswith('{}web'.format(os.path.sep))) + def test_config_invalid_ipam_config(self): with pytest.raises(ConfigurationError) as excinfo: config.load(