Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions fig/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def run(self, project, options):
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`
Expand Down Expand Up @@ -320,6 +321,10 @@ def run(self, project, options):

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,
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/user-figfile/fig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service:
image: busybox:latest
command: id
17 changes: 17 additions & 0 deletions tests/integration/cli_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from __future__ import absolute_import
import sys

from docker.errors import APIError
from six import StringIO
from mock import patch

from .testcases import DockerClientTestCase
from fig.cli.main import TopLevelCommand



class CLITestCase(DockerClientTestCase):
def setUp(self):
super(CLITestCase, self).setUp()
Expand Down Expand Up @@ -217,6 +219,21 @@ def test_run_service_with_entrypoint_overridden(self, _):
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'
Expand Down