From 59c8ed77e4e8a54c5a7a7d645a73feed43ef140d Mon Sep 17 00:00:00 2001 From: Ganesh Satpute Date: Sun, 28 Jan 2018 16:45:38 +0530 Subject: [PATCH 1/2] Allow unset of entrypoint (resolves #5582) When an empty string is passed to the 'entrypoint' parameter, for example `docker-compose run --entrypoint='' ...` OR `docker-compose run --entrypoint '' ...` It allows the default entrypoint to be overriden by empty value. Signed-off-by: Ganesh Satpute --- compose/cli/main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/compose/cli/main.py b/compose/cli/main.py index aff69c2d3..056d8c46f 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -1232,8 +1232,7 @@ def build_container_options(options, detach, command): if options['--label']: container_options['labels'] = parse_labels(options['--label']) - if options['--entrypoint']: - container_options['entrypoint'] = options.get('--entrypoint') + _build_container_entrypoint_options(container_options, options) if options['--rm']: container_options['restart'] = None @@ -1260,6 +1259,16 @@ def build_container_options(options, detach, command): return container_options +def _build_container_entrypoint_options(container_options, options): + if options['--entrypoint']: + if options['--entrypoint'].strip() == '': + # Set an empty entry point. Refer https://github.com/moby/moby/pull/23718 + log.info("Overriding the entrypoint") + container_options['entrypoint'] = [""] + else: + container_options['entrypoint'] = options.get('--entrypoint') + + def run_one_off_container(container_options, project, service, options, toplevel_options, project_dir='.'): if not options['--no-deps']: From 1096a903be0b5897af8995cec4cccac9d20d880c Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Tue, 27 Feb 2018 12:57:58 -0800 Subject: [PATCH 2/2] unset entrypoint test Signed-off-by: Joffrey F --- compose/cli/main.py | 15 ++++----------- tests/acceptance/cli_test.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/compose/cli/main.py b/compose/cli/main.py index 056d8c46f..62de35fec 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -1232,7 +1232,10 @@ def build_container_options(options, detach, command): if options['--label']: container_options['labels'] = parse_labels(options['--label']) - _build_container_entrypoint_options(container_options, options) + if options.get('--entrypoint') is not None: + container_options['entrypoint'] = ( + [""] if options['--entrypoint'] == '' else options['--entrypoint'] + ) if options['--rm']: container_options['restart'] = None @@ -1259,16 +1262,6 @@ def build_container_options(options, detach, command): return container_options -def _build_container_entrypoint_options(container_options, options): - if options['--entrypoint']: - if options['--entrypoint'].strip() == '': - # Set an empty entry point. Refer https://github.com/moby/moby/pull/23718 - log.info("Overriding the entrypoint") - container_options['entrypoint'] = [""] - else: - container_options['entrypoint'] = options.get('--entrypoint') - - def run_one_off_container(container_options, project, service, options, toplevel_options, project_dir='.'): if not options['--no-deps']: diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index 42b487aab..a8d93bfe8 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -1697,6 +1697,18 @@ class CLITestCase(DockerClientTestCase): assert container.get('Config.Entrypoint') == ['printf'] assert container.get('Config.Cmd') == ['default', 'args'] + def test_run_service_with_unset_entrypoint(self): + self.base_dir = 'tests/fixtures/entrypoint-dockerfile' + self.dispatch(['run', '--entrypoint=""', 'test', 'true']) + container = self.project.containers(stopped=True, one_off=OneOffFilter.only)[0] + assert container.get('Config.Entrypoint') is None + assert container.get('Config.Cmd') == ['true'] + + self.dispatch(['run', '--entrypoint', '""', 'test', 'true']) + container = self.project.containers(stopped=True, one_off=OneOffFilter.only)[0] + assert container.get('Config.Entrypoint') is None + assert container.get('Config.Cmd') == ['true'] + def test_run_service_with_dockerfile_entrypoint_overridden(self): self.base_dir = 'tests/fixtures/entrypoint-dockerfile' self.dispatch(['run', '--entrypoint', 'echo', 'test'])