mirror of https://github.com/docker/compose.git
Allow overriding environements on command line
Add a new command line option -e to override environement variables when running a service. Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>
This commit is contained in:
parent
872a1b5a5c
commit
92249364b6
|
@ -261,12 +261,13 @@ class TopLevelCommand(Command):
|
||||||
running. If you do not want to start linked services, use
|
running. If you do not want to start linked services, use
|
||||||
`fig run --no-deps SERVICE COMMAND [ARGS...]`.
|
`fig run --no-deps SERVICE COMMAND [ARGS...]`.
|
||||||
|
|
||||||
Usage: run [options] SERVICE [COMMAND] [ARGS...]
|
Usage: run [options] [-e KEY=VAL...] SERVICE [COMMAND] [ARGS...]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-d Detached mode: Run container in the background, print
|
-d Detached mode: Run container in the background, print
|
||||||
new container name.
|
new container name.
|
||||||
--entrypoint CMD Override the entrypoint of the image.
|
--entrypoint CMD Override the entrypoint of the image.
|
||||||
|
-e KEY=VAL Set an environment variable (can be used multiple times)
|
||||||
--no-deps Don't start linked services.
|
--no-deps Don't start linked services.
|
||||||
--rm Remove container after run. Ignored in detached mode.
|
--rm Remove container after run. Ignored in detached mode.
|
||||||
-T Disable pseudo-tty allocation. By default `fig run`
|
-T Disable pseudo-tty allocation. By default `fig run`
|
||||||
|
@ -299,6 +300,13 @@ class TopLevelCommand(Command):
|
||||||
'stdin_open': not options['-d'],
|
'stdin_open': not options['-d'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options['-e']:
|
||||||
|
for option in options['-e']:
|
||||||
|
if 'environment' not in service.options:
|
||||||
|
service.options['environment'] = {}
|
||||||
|
k, v = option.split('=', 1)
|
||||||
|
service.options['environment'][k] = v
|
||||||
|
|
||||||
if options['--entrypoint']:
|
if options['--entrypoint']:
|
||||||
container_options['entrypoint'] = options.get('--entrypoint')
|
container_options['entrypoint'] = options.get('--entrypoint')
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
service:
|
||||||
|
image: busybox:latest
|
||||||
|
command: sleep 5
|
||||||
|
|
||||||
|
environment:
|
||||||
|
foo: bar
|
||||||
|
hello: world
|
|
@ -206,6 +206,26 @@ class CLITestCase(DockerClientTestCase):
|
||||||
u'/bin/echo helloworld'
|
u'/bin/echo helloworld'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@patch('dockerpty.start')
|
||||||
|
def test_run_service_with_environement_overridden(self, _):
|
||||||
|
name = 'service'
|
||||||
|
self.command.base_dir = 'tests/fixtures/environment-figfile'
|
||||||
|
self.command.dispatch(
|
||||||
|
['run', '-e', 'foo=notbar', '-e', 'allo=moto=bobo',
|
||||||
|
'-e', 'alpha=beta', name],
|
||||||
|
None
|
||||||
|
)
|
||||||
|
service = self.project.get_service(name)
|
||||||
|
container = service.containers(stopped=True, one_off=True)[0]
|
||||||
|
# env overriden
|
||||||
|
self.assertEqual('notbar', container.environment['foo'])
|
||||||
|
# keep environement from yaml
|
||||||
|
self.assertEqual('world', container.environment['hello'])
|
||||||
|
# added option from command line
|
||||||
|
self.assertEqual('beta', container.environment['alpha'])
|
||||||
|
# make sure a value with a = don't crash out
|
||||||
|
self.assertEqual('moto=bobo', container.environment['allo'])
|
||||||
|
|
||||||
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