Skip to content

Commit ed12f25

Browse files
committed
Merge pull request #511 from bfirsh/support_entrypoint
Add support for entrypoint to "fig run"
2 parents 267be12 + 0dc19cb commit ed12f25

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

fig/cli/main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,11 @@ def run(self, project, options):
258258
Options:
259259
-d Detached mode: Run container in the background, print
260260
new container name.
261+
--entrypoint Override the entrypoint of the image.
262+
--no-deps Don't start linked services.
263+
--rm Remove container after run. Ignored in detached mode.
261264
-T Disable pseudo-tty allocation. By default `fig run`
262265
allocates a TTY.
263-
--rm Remove container after run. Ignored in detached mode.
264-
--no-deps Don't start linked services.
265266
"""
266267
service = project.get_service(options['SERVICE'])
267268

@@ -289,6 +290,10 @@ def run(self, project, options):
289290
'tty': tty,
290291
'stdin_open': not options['-d'],
291292
}
293+
294+
if options['--entrypoint']:
295+
container_options['entrypoint'] = options.get('--entrypoint')
296+
292297
container = service.create_container(one_off=True, **container_options)
293298
if options['-d']:
294299
service.start_container(container, ports=None, one_off=True)

fig/container.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ def human_readable_state(self):
8989

9090
@property
9191
def human_readable_command(self):
92-
return ' '.join(self.get('Config.Cmd') or '')
92+
entrypoint = self.get('Config.Entrypoint') or []
93+
cmd = self.get('Config.Cmd') or []
94+
return ' '.join(entrypoint + cmd)
9395

9496
@property
9597
def environment(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM busybox:latest
2+
ENTRYPOINT echo "From prebuilt entrypoint"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
service:
2+
build: tests/fixtures/dockerfile_with_entrypoint

tests/integration/cli_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,21 @@ def test_run_without_command(self, __):
191191
[u'/bin/true'],
192192
)
193193

194+
@patch('dockerpty.start')
195+
def test_run_service_with_entrypoint_overridden(self, _):
196+
self.command.base_dir = 'tests/fixtures/dockerfile_with_entrypoint'
197+
name = 'service'
198+
self.command.dispatch(
199+
['run', '--entrypoint', '/bin/echo', name, 'helloworld'],
200+
None
201+
)
202+
service = self.project.get_service(name)
203+
container = service.containers(stopped=True, one_off=True)[0]
204+
self.assertEqual(
205+
container.human_readable_command,
206+
u'/bin/echo helloworld'
207+
)
208+
194209
def test_rm(self):
195210
service = self.project.get_service('simple')
196211
service.create_container()

0 commit comments

Comments
 (0)