Allow overriding user on the command line

Allow overriding a user on the command line from the one specified in
the fig.yaml

We are testing on the behavior of how the busybox image is made which is
kind of tricky but hopefully that shouln't change.

Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>
This commit is contained in:
Chmouel Boudjnah 2014-12-17 13:59:52 +01:00
parent 200c44cff3
commit f2f01e207b
3 changed files with 25 additions and 0 deletions

View File

@ -276,6 +276,7 @@ class TopLevelCommand(Command):
new container name.
--entrypoint CMD Override the entrypoint of the image.
-e KEY=VAL Set an environment variable (can be used multiple times)
-u --user USER Run as specified user.
--no-deps Don't start linked services.
--rm Remove container after run. Ignored in detached mode.
-T Disable pseudo-tty allocation. By default `fig run`
@ -320,6 +321,10 @@ class TopLevelCommand(Command):
if options['--entrypoint']:
container_options['entrypoint'] = options.get('--entrypoint')
if options['--user']:
container_options['user'] = options.get('--user')
container = service.create_container(
one_off=True,
insecure_registry=insecure_registry,

3
tests/fixtures/user-figfile/fig.yml vendored Normal file
View File

@ -0,0 +1,3 @@
service:
image: busybox:latest
command: id

View File

@ -1,6 +1,7 @@
from __future__ import absolute_import
import sys
from docker.errors import APIError
from six import StringIO
from mock import patch
@ -8,6 +9,7 @@ from .testcases import DockerClientTestCase
from fig.cli.main import TopLevelCommand
class CLITestCase(DockerClientTestCase):
def setUp(self):
super(CLITestCase, self).setUp()
@ -217,6 +219,21 @@ class CLITestCase(DockerClientTestCase):
u'/bin/echo helloworld'
)
@patch('dockerpty.start')
def test_run_service_with_user_overridden(self, _):
name = 'service'
self.command.base_dir = 'tests/fixtures/user-figfile'
# NOTE(chmou): available in default busybox and has a shell
user = 'sshd'
args = ['run', '--user', user, name]
self.command.dispatch(args, None)
service = self.project.get_service(name)
container = service.containers(stopped=True, one_off=True)[0]
container.inspect()
self.assertEqual(user, container.dictionary['Config']['User'])
@patch('dockerpty.start')
def test_run_service_with_environement_overridden(self, _):
name = 'service'