mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Split off build_container_options() to reduce the complexity of run
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
658803edf8
commit
52b791a264
@ -538,48 +538,18 @@ class TopLevelCommand(object):
|
|||||||
"Please pass the -d flag when using `docker-compose run`."
|
"Please pass the -d flag when using `docker-compose run`."
|
||||||
)
|
)
|
||||||
|
|
||||||
if options['COMMAND']:
|
|
||||||
command = [options['COMMAND']] + options['ARGS']
|
|
||||||
else:
|
|
||||||
command = service.options.get('command')
|
|
||||||
|
|
||||||
container_options = {
|
|
||||||
'command': command,
|
|
||||||
'tty': not (detach or options['-T'] or not sys.stdin.isatty()),
|
|
||||||
'stdin_open': not detach,
|
|
||||||
'detach': detach,
|
|
||||||
}
|
|
||||||
|
|
||||||
if options['-e']:
|
|
||||||
container_options['environment'] = parse_environment(options['-e'])
|
|
||||||
|
|
||||||
if options['--entrypoint']:
|
|
||||||
container_options['entrypoint'] = options.get('--entrypoint')
|
|
||||||
|
|
||||||
if options['--rm']:
|
|
||||||
container_options['restart'] = None
|
|
||||||
|
|
||||||
if options['--user']:
|
|
||||||
container_options['user'] = options.get('--user')
|
|
||||||
|
|
||||||
if not options['--service-ports']:
|
|
||||||
container_options['ports'] = []
|
|
||||||
|
|
||||||
if options['--publish']:
|
|
||||||
container_options['ports'] = options.get('--publish')
|
|
||||||
|
|
||||||
if options['--publish'] and options['--service-ports']:
|
if options['--publish'] and options['--service-ports']:
|
||||||
raise UserError(
|
raise UserError(
|
||||||
'Service port mapping and manual port mapping '
|
'Service port mapping and manual port mapping '
|
||||||
'can not be used togather'
|
'can not be used togather'
|
||||||
)
|
)
|
||||||
|
|
||||||
if options['--name']:
|
if options['COMMAND']:
|
||||||
container_options['name'] = options['--name']
|
command = [options['COMMAND']] + options['ARGS']
|
||||||
|
else:
|
||||||
if options['--workdir']:
|
command = service.options.get('command')
|
||||||
container_options['working_dir'] = options['--workdir']
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
def scale(self, options):
|
def scale(self, options):
|
||||||
@ -780,6 +750,41 @@ def build_action_from_opts(options):
|
|||||||
return BuildAction.none
|
return BuildAction.none
|
||||||
|
|
||||||
|
|
||||||
|
def build_container_options(options, detach, command):
|
||||||
|
container_options = {
|
||||||
|
'command': command,
|
||||||
|
'tty': not (detach or options['-T'] or not sys.stdin.isatty()),
|
||||||
|
'stdin_open': not detach,
|
||||||
|
'detach': detach,
|
||||||
|
}
|
||||||
|
|
||||||
|
if options['-e']:
|
||||||
|
container_options['environment'] = parse_environment(options['-e'])
|
||||||
|
|
||||||
|
if options['--entrypoint']:
|
||||||
|
container_options['entrypoint'] = options.get('--entrypoint')
|
||||||
|
|
||||||
|
if options['--rm']:
|
||||||
|
container_options['restart'] = None
|
||||||
|
|
||||||
|
if options['--user']:
|
||||||
|
container_options['user'] = options.get('--user')
|
||||||
|
|
||||||
|
if not options['--service-ports']:
|
||||||
|
container_options['ports'] = []
|
||||||
|
|
||||||
|
if options['--publish']:
|
||||||
|
container_options['ports'] = options.get('--publish')
|
||||||
|
|
||||||
|
if options['--name']:
|
||||||
|
container_options['name'] = options['--name']
|
||||||
|
|
||||||
|
if options['--workdir']:
|
||||||
|
container_options['working_dir'] = options['--workdir']
|
||||||
|
|
||||||
|
return container_options
|
||||||
|
|
||||||
|
|
||||||
def run_one_off_container(container_options, project, service, options):
|
def run_one_off_container(container_options, project, service, options):
|
||||||
if not options['--no-deps']:
|
if not options['--no-deps']:
|
||||||
deps = service.get_dependency_names()
|
deps = service.get_dependency_names()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user