mirror of https://github.com/docker/compose.git
Unset env vars behavior in 'run' mirroring engine
Unset env vars passed to `run` via command line options take the value of the system's var with the same name. Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
3d20e25bf8
commit
5d244ef6d8
|
@ -891,7 +891,9 @@ def build_container_options(options, detach, command):
|
||||||
}
|
}
|
||||||
|
|
||||||
if options['-e']:
|
if options['-e']:
|
||||||
container_options['environment'] = parse_environment(options['-e'])
|
container_options['environment'] = Environment.from_command_line(
|
||||||
|
parse_environment(options['-e'])
|
||||||
|
)
|
||||||
|
|
||||||
if options['--entrypoint']:
|
if options['--entrypoint']:
|
||||||
container_options['entrypoint'] = options.get('--entrypoint')
|
container_options['entrypoint'] = options.get('--entrypoint')
|
||||||
|
|
|
@ -60,6 +60,18 @@ class Environment(dict):
|
||||||
instance.update(os.environ)
|
instance.update(os.environ)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_command_line(cls, parsed_env_opts):
|
||||||
|
result = cls()
|
||||||
|
for k, v in parsed_env_opts.items():
|
||||||
|
# Values from the command line take priority, unless they're unset
|
||||||
|
# in which case they take the value from the system's environment
|
||||||
|
if v is None and k in os.environ:
|
||||||
|
result[k] = os.environ[k]
|
||||||
|
else:
|
||||||
|
result[k] = v
|
||||||
|
return result
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
try:
|
try:
|
||||||
return super(Environment, self).__getitem__(key)
|
return super(Environment, self).__getitem__(key)
|
||||||
|
|
|
@ -1216,6 +1216,14 @@ class CLITestCase(DockerClientTestCase):
|
||||||
'simplecomposefile_simple_run_1',
|
'simplecomposefile_simple_run_1',
|
||||||
'exited'))
|
'exited'))
|
||||||
|
|
||||||
|
@mock.patch.dict(os.environ)
|
||||||
|
def test_run_env_values_from_system(self):
|
||||||
|
os.environ['FOO'] = 'bar'
|
||||||
|
os.environ['BAR'] = 'baz'
|
||||||
|
result = self.dispatch(['run', '-e', 'FOO', 'simple', 'env'], None)
|
||||||
|
assert 'FOO=bar' in result.stdout
|
||||||
|
assert 'BAR=baz' not in result.stdout
|
||||||
|
|
||||||
def test_rm(self):
|
def test_rm(self):
|
||||||
service = self.project.get_service('simple')
|
service = self.project.get_service('simple')
|
||||||
service.create_container()
|
service.create_container()
|
||||||
|
|
Loading…
Reference in New Issue