Added env var parsing to volume container paths

This commit adds environment variable parsing to the container side
of the volume mapping in configs. The common use case for this is
mounting SSH agent sockets in a container, using code like:

volumes:
    - $SSH_AUTH_SOCK:$SSH_AUTH_SOCK
environment:
    - SSH_AUTH_SOCK

Signed-off-by: Jeff Kramer <jeff.kramer@voxmedia.com>
This commit is contained in:
Jeff Kramer 2015-07-02 12:51:40 -05:00
commit 8709dc3c24
2 changed files with 26 additions and 7 deletions

View file

@ -334,6 +334,25 @@ class EnvTest(unittest.TestCase):
{'FILE_DEF': 'F1', 'FILE_DEF_EMPTY': '', 'ENV_DEF': 'E3', 'NO_DEF': ''},
)
@mock.patch.dict(os.environ)
def test_resolve_path(self):
os.environ['HOSTENV'] = '/tmp'
os.environ['CONTAINERENV'] = '/host/tmp'
service_dict = config.make_service_dict(
'foo',
{'volumes': ['$HOSTENV:$CONTAINERENV']},
working_dir="tests/fixtures/env"
)
self.assertEqual(set(service_dict['volumes']), set(['/tmp:/host/tmp']))
service_dict = config.make_service_dict(
'foo',
{'volumes': ['/opt${HOSTENV}:/opt${CONTAINERENV}']},
working_dir="tests/fixtures/env"
)
self.assertEqual(set(service_dict['volumes']), set(['/opt/tmp:/opt/host/tmp']))
class ExtendsTest(unittest.TestCase):
def test_extends(self):