|
|
@@ -122,7 +122,7 @@ def perform_command(options, handler, command_options):
|
|
|
return
|
|
|
|
|
|
project = project_from_options('.', options)
|
|
|
- command = TopLevelCommand(project)
|
|
|
+ command = TopLevelCommand(project, options=options)
|
|
|
with errors.handle_connection_errors(project.client):
|
|
|
handler(command, command_options)
|
|
|
|
|
|
@@ -157,16 +157,17 @@ def setup_console_handler(handler, verbose, noansi=False, level=None):
|
|
|
|
|
|
if level is not None:
|
|
|
levels = {
|
|
|
- 'DEBUG': logging.DEBUG,
|
|
|
- 'INFO': logging.INFO,
|
|
|
- 'WARNING': logging.WARNING,
|
|
|
- 'ERROR': logging.ERROR,
|
|
|
- 'CRITICAL': logging.CRITICAL,
|
|
|
+ 'DEBUG': logging.DEBUG,
|
|
|
+ 'INFO': logging.INFO,
|
|
|
+ 'WARNING': logging.WARNING,
|
|
|
+ 'ERROR': logging.ERROR,
|
|
|
+ 'CRITICAL': logging.CRITICAL,
|
|
|
}
|
|
|
loglevel = levels.get(level.upper())
|
|
|
if loglevel is None:
|
|
|
- raise UserError('Invalid value for --log-level. Expected one of '
|
|
|
- + 'DEBUG, INFO, WARNING, ERROR, CRITICAL.')
|
|
|
+ raise UserError(
|
|
|
+ 'Invalid value for --log-level. Expected one of DEBUG, INFO, WARNING, ERROR, CRITICAL.'
|
|
|
+ )
|
|
|
|
|
|
handler.setLevel(loglevel)
|
|
|
|
|
|
@@ -237,9 +238,10 @@ class TopLevelCommand(object):
|
|
|
version Show the Docker-Compose version information
|
|
|
"""
|
|
|
|
|
|
- def __init__(self, project, project_dir='.'):
|
|
|
+ def __init__(self, project, project_dir='.', options=None):
|
|
|
self.project = project
|
|
|
self.project_dir = '.'
|
|
|
+ self.toplevel_options = options or {}
|
|
|
|
|
|
def build(self, options):
|
|
|
"""
|
|
|
@@ -475,7 +477,10 @@ class TopLevelCommand(object):
|
|
|
tty = not options["-T"]
|
|
|
|
|
|
if IS_WINDOWS_PLATFORM or use_cli and not detach:
|
|
|
- sys.exit(call_docker(build_exec_command(options, container.id, command)))
|
|
|
+ sys.exit(call_docker(
|
|
|
+ build_exec_command(options, container.id, command),
|
|
|
+ self.toplevel_options)
|
|
|
+ )
|
|
|
|
|
|
create_exec_options = {
|
|
|
"privileged": options["--privileged"],
|
|
|
@@ -820,7 +825,10 @@ class TopLevelCommand(object):
|
|
|
command = service.options.get('command')
|
|
|
|
|
|
container_options = build_container_options(options, detach, command)
|
|
|
- run_one_off_container(container_options, self.project, service, options, self.project_dir)
|
|
|
+ run_one_off_container(
|
|
|
+ container_options, self.project, service, options,
|
|
|
+ self.toplevel_options, self.project_dir
|
|
|
+ )
|
|
|
|
|
|
def scale(self, options):
|
|
|
"""
|
|
|
@@ -1253,7 +1261,8 @@ def build_container_options(options, detach, command):
|
|
|
return container_options
|
|
|
|
|
|
|
|
|
-def run_one_off_container(container_options, project, service, options, project_dir='.'):
|
|
|
+def run_one_off_container(container_options, project, service, options, toplevel_options,
|
|
|
+ project_dir='.'):
|
|
|
if not options['--no-deps']:
|
|
|
deps = service.get_dependency_names()
|
|
|
if deps:
|
|
|
@@ -1289,7 +1298,10 @@ def run_one_off_container(container_options, project, service, options, project_
|
|
|
try:
|
|
|
if IS_WINDOWS_PLATFORM or use_cli:
|
|
|
service.connect_container_to_networks(container)
|
|
|
- exit_code = call_docker(["start", "--attach", "--interactive", container.id])
|
|
|
+ exit_code = call_docker(
|
|
|
+ ["start", "--attach", "--interactive", container.id],
|
|
|
+ toplevel_options
|
|
|
+ )
|
|
|
else:
|
|
|
operation = RunOperation(
|
|
|
project.client,
|
|
|
@@ -1368,12 +1380,32 @@ def exit_if(condition, message, exit_code):
|
|
|
raise SystemExit(exit_code)
|
|
|
|
|
|
|
|
|
-def call_docker(args):
|
|
|
+def call_docker(args, dockeropts):
|
|
|
executable_path = find_executable('docker')
|
|
|
if not executable_path:
|
|
|
raise UserError(errors.docker_not_found_msg("Couldn't find `docker` binary."))
|
|
|
|
|
|
- args = [executable_path] + args
|
|
|
+ tls = dockeropts.get('--tls', False)
|
|
|
+ ca_cert = dockeropts.get('--tlscacert')
|
|
|
+ cert = dockeropts.get('--tlscert')
|
|
|
+ key = dockeropts.get('--tlskey')
|
|
|
+ verify = dockeropts.get('--tlsverify')
|
|
|
+ host = dockeropts.get('--host')
|
|
|
+ tls_options = []
|
|
|
+ if tls:
|
|
|
+ tls_options.append('--tls')
|
|
|
+ if ca_cert:
|
|
|
+ tls_options.extend(['--tlscacert', ca_cert])
|
|
|
+ if cert:
|
|
|
+ tls_options.extend(['--tlscert', cert])
|
|
|
+ if key:
|
|
|
+ tls_options.extend(['--tlskey', key])
|
|
|
+ if verify:
|
|
|
+ tls_options.append('--tlsverify')
|
|
|
+ if host:
|
|
|
+ tls_options.extend(['--host', host])
|
|
|
+
|
|
|
+ args = [executable_path] + tls_options + args
|
|
|
log.debug(" ".join(map(pipes.quote, args)))
|
|
|
|
|
|
return subprocess.call(args)
|