Skip to content

Commit

Permalink
Add support for --env-file option pass through (osrf#82)
Browse files Browse the repository at this point in the history
Signed-off-by: Tully Foote <tfoote@osrfoundation.org>
  • Loading branch information
tfoote authored May 8, 2020
1 parent 413d25a commit 135e73f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/rocker/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,15 @@ def get_snippet(self, cli_args):
def get_docker_args(self, cli_args):
args = ['']

envs = [ x for sublist in cli_args['env'] for x in sublist]
for env in envs:
args.append('-e {0}'.format(quote(env)))
if cli_args.get('env'):
envs = [ x for sublist in cli_args['env'] for x in sublist]
for env in envs:
args.append('-e {0}'.format(quote(env)))

if cli_args.get('env_file'):
env_files = [ x for sublist in cli_args['env_file'] for x in sublist]
for env_file in env_files:
args.append('--env-file {0}'.format(quote(env_file)))

return ' '.join(args)

Expand All @@ -229,3 +235,13 @@ def register_arguments(parser):
nargs='+',
action='append',
help='set environment variables')
parser.add_argument('--env-file',
type=str,
nargs=1,
action='append',
help='set environment variable via env-file')

@classmethod
def check_args_for_activation(cls, cli_args):
""" Returns true if the arguments indicate that this extension should be activated otherwise false."""
return True if cli_args.get('env') or cli_args.get('env_file') else False
14 changes: 14 additions & 0 deletions test/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,17 @@ def test_env_extension(self):
self.assertEqual(p.get_snippet(mock_cliargs), '')
self.assertEqual(p.get_preamble(mock_cliargs), '')
self.assertEqual(p.get_docker_args(mock_cliargs), ' -e ENVVARNAME=envvar_value -e ENV2=val2 -e ENV3=val3')

def test_env_file_extension(self):
plugins = list_plugins()
env_plugin = plugins['env']
self.assertEqual(env_plugin.get_name(), 'env')

p = env_plugin()
self.assertTrue(plugin_load_parser_correctly(env_plugin))

mock_cliargs = {'env_file': [['foo'], ['bar']]}

self.assertEqual(p.get_snippet(mock_cliargs), '')
self.assertEqual(p.get_preamble(mock_cliargs), '')
self.assertEqual(p.get_docker_args(mock_cliargs), ' --env-file foo --env-file bar')

0 comments on commit 135e73f

Please sign in to comment.