mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Also use docker CLI for interactive one-off runs.
COMPOSE_EXEC_NO_CLI -> COMPOSE_INTERACTIVE_NO_CLI Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
f4d7d32280
commit
a5d8c68d42
@ -435,7 +435,7 @@ class TopLevelCommand(object):
|
|||||||
not supported in API < 1.25)
|
not supported in API < 1.25)
|
||||||
"""
|
"""
|
||||||
environment = Environment.from_env_file(self.project_dir)
|
environment = Environment.from_env_file(self.project_dir)
|
||||||
use_cli = not environment.get_boolean('COMPOSE_EXEC_NO_CLI')
|
use_cli = not environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
||||||
index = int(options.get('--index'))
|
index = int(options.get('--index'))
|
||||||
service = self.project.get_service(options['SERVICE'])
|
service = self.project.get_service(options['SERVICE'])
|
||||||
detach = options['-d']
|
detach = options['-d']
|
||||||
@ -794,7 +794,7 @@ class TopLevelCommand(object):
|
|||||||
command = service.options.get('command')
|
command = service.options.get('command')
|
||||||
|
|
||||||
container_options = build_container_options(options, detach, command)
|
container_options = build_container_options(options, detach, command)
|
||||||
run_one_off_container(container_options, self.project, service, options)
|
run_one_off_container(container_options, self.project, service, options, self.project_dir)
|
||||||
|
|
||||||
def scale(self, options):
|
def scale(self, options):
|
||||||
"""
|
"""
|
||||||
@ -1201,7 +1201,7 @@ def build_container_options(options, detach, command):
|
|||||||
return container_options
|
return container_options
|
||||||
|
|
||||||
|
|
||||||
def run_one_off_container(container_options, project, service, options):
|
def run_one_off_container(container_options, project, service, options, project_dir='.'):
|
||||||
if not options['--no-deps']:
|
if not options['--no-deps']:
|
||||||
deps = service.get_dependency_names()
|
deps = service.get_dependency_names()
|
||||||
if deps:
|
if deps:
|
||||||
@ -1228,10 +1228,13 @@ def run_one_off_container(container_options, project, service, options):
|
|||||||
if options['--rm']:
|
if options['--rm']:
|
||||||
project.client.remove_container(container.id, force=True, v=True)
|
project.client.remove_container(container.id, force=True, v=True)
|
||||||
|
|
||||||
|
environment = Environment.from_env_file(project_dir)
|
||||||
|
use_cli = not environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
||||||
|
|
||||||
signals.set_signal_handler_to_shutdown()
|
signals.set_signal_handler_to_shutdown()
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
if IS_WINDOWS_PLATFORM:
|
if IS_WINDOWS_PLATFORM or use_cli:
|
||||||
service.connect_container_to_networks(container)
|
service.connect_container_to_networks(container)
|
||||||
exit_code = call_docker(["start", "--attach", "--interactive", container.id])
|
exit_code = call_docker(["start", "--attach", "--interactive", container.id])
|
||||||
else:
|
else:
|
||||||
|
@ -97,7 +97,9 @@ class CLITestCase(unittest.TestCase):
|
|||||||
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason="requires dockerpty")
|
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason="requires dockerpty")
|
||||||
@mock.patch('compose.cli.main.RunOperation', autospec=True)
|
@mock.patch('compose.cli.main.RunOperation', autospec=True)
|
||||||
@mock.patch('compose.cli.main.PseudoTerminal', autospec=True)
|
@mock.patch('compose.cli.main.PseudoTerminal', autospec=True)
|
||||||
|
@mock.patch.dict(os.environ)
|
||||||
def test_run_interactive_passes_logs_false(self, mock_pseudo_terminal, mock_run_operation):
|
def test_run_interactive_passes_logs_false(self, mock_pseudo_terminal, mock_run_operation):
|
||||||
|
os.environ['COMPOSE_INTERACTIVE_NO_CLI'] = 'true'
|
||||||
mock_client = mock.create_autospec(docker.APIClient)
|
mock_client = mock.create_autospec(docker.APIClient)
|
||||||
mock_client.api_version = DEFAULT_DOCKER_API_VERSION
|
mock_client.api_version = DEFAULT_DOCKER_API_VERSION
|
||||||
project = Project.from_config(
|
project = Project.from_config(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user