246 | 246 |
def project_dir(self):
|
247 | 247 |
return self.toplevel_options.get('--project-directory') or '.'
|
248 | 248 |
|
|
249 |
@property
|
|
250 |
def toplevel_environment(self):
|
|
251 |
environment_file = self.toplevel_options.get('--env-file')
|
|
252 |
return Environment.from_env_file(self.project_dir, environment_file)
|
|
253 |
|
249 | 254 |
def build(self, options):
|
250 | 255 |
"""
|
251 | 256 |
Build or rebuild services.
|
|
275 | 280 |
'--build-arg is only supported when services are specified for API version < 1.25.'
|
276 | 281 |
' Please use a Compose file version > 2.2 or specify which services to build.'
|
277 | 282 |
)
|
278 | |
environment_file = options.get('--env-file')
|
279 | |
environment = Environment.from_env_file(self.project_dir, environment_file)
|
280 | |
build_args = resolve_build_args(build_args, environment)
|
|
283 |
build_args = resolve_build_args(build_args, self.toplevel_environment)
|
281 | 284 |
|
282 | 285 |
self.project.build(
|
283 | 286 |
service_names=options['SERVICE'],
|
|
428 | 431 |
Compose file
|
429 | 432 |
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
|
430 | 433 |
(default: 10)
|
431 | |
--env-file PATH Specify an alternate environment file
|
432 | |
"""
|
433 | |
environment_file = options.get('--env-file')
|
434 | |
environment = Environment.from_env_file(self.project_dir, environment_file)
|
435 | |
ignore_orphans = environment.get_boolean('COMPOSE_IGNORE_ORPHANS')
|
|
434 |
"""
|
|
435 |
ignore_orphans = self.toplevel_environment.get_boolean('COMPOSE_IGNORE_ORPHANS')
|
436 | 436 |
|
437 | 437 |
if ignore_orphans and options['--remove-orphans']:
|
438 | 438 |
raise UserError("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined.")
|
|
488 | 488 |
-e, --env KEY=VAL Set environment variables (can be used multiple times,
|
489 | 489 |
not supported in API < 1.25)
|
490 | 490 |
-w, --workdir DIR Path to workdir directory for this command.
|
491 | |
--env-file PATH Specify an alternate environment file
|
492 | |
"""
|
493 | |
environment_file = options.get('--env-file')
|
494 | |
environment = Environment.from_env_file(self.project_dir, environment_file)
|
495 | |
use_cli = not environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
|
491 |
"""
|
|
492 |
use_cli = not self.toplevel_environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
496 | 493 |
index = int(options.get('--index'))
|
497 | 494 |
service = self.project.get_service(options['SERVICE'])
|
498 | 495 |
detach = options.get('--detach')
|
|
515 | 512 |
if IS_WINDOWS_PLATFORM or use_cli and not detach:
|
516 | 513 |
sys.exit(call_docker(
|
517 | 514 |
build_exec_command(options, container.id, command),
|
518 | |
self.toplevel_options, environment)
|
|
515 |
self.toplevel_options, self.toplevel_environment)
|
519 | 516 |
)
|
520 | 517 |
|
521 | 518 |
create_exec_options = {
|
|
889 | 886 |
container_options = build_one_off_container_options(options, detach, command)
|
890 | 887 |
run_one_off_container(
|
891 | 888 |
container_options, self.project, service, options,
|
892 | |
self.toplevel_options, self.project_dir
|
|
889 |
self.toplevel_options, self.toplevel_environment
|
893 | 890 |
)
|
894 | 891 |
|
895 | 892 |
def scale(self, options):
|
|
1050 | 1047 |
container. Implies --abort-on-container-exit.
|
1051 | 1048 |
--scale SERVICE=NUM Scale SERVICE to NUM instances. Overrides the
|
1052 | 1049 |
`scale` setting in the Compose file if present.
|
1053 | |
--env-file PATH Specify an alternate environment file
|
1054 | 1050 |
"""
|
1055 | 1051 |
start_deps = not options['--no-deps']
|
1056 | 1052 |
always_recreate_deps = options['--always-recreate-deps']
|
|
1065 | 1061 |
if detached and (cascade_stop or exit_value_from):
|
1066 | 1062 |
raise UserError("--abort-on-container-exit and -d cannot be combined.")
|
1067 | 1063 |
|
1068 | |
environment_file = options.get('--env-file')
|
1069 | |
environment = Environment.from_env_file(self.project_dir, environment_file)
|
1070 | |
ignore_orphans = environment.get_boolean('COMPOSE_IGNORE_ORPHANS')
|
|
1064 |
ignore_orphans = self.toplevel_environment.get_boolean('COMPOSE_IGNORE_ORPHANS')
|
1071 | 1065 |
|
1072 | 1066 |
if ignore_orphans and remove_orphans:
|
1073 | 1067 |
raise UserError("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined.")
|
|
1330 | 1324 |
|
1331 | 1325 |
|
1332 | 1326 |
def run_one_off_container(container_options, project, service, options, toplevel_options,
|
1333 | |
project_dir='.'):
|
|
1327 |
toplevel_environment):
|
1334 | 1328 |
if not options['--no-deps']:
|
1335 | 1329 |
deps = service.get_dependency_names()
|
1336 | 1330 |
if deps:
|
|
1359 | 1353 |
if options['--rm']:
|
1360 | 1354 |
project.client.remove_container(container.id, force=True, v=True)
|
1361 | 1355 |
|
1362 | |
environment_file = options.get('--env-file')
|
1363 | |
environment = Environment.from_env_file(project_dir, environment_file)
|
1364 | |
use_cli = not environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
|
1356 |
use_cli = not toplevel_environment.get_boolean('COMPOSE_INTERACTIVE_NO_CLI')
|
|
1357 |
|
1365 | 1358 |
signals.set_signal_handler_to_shutdown()
|
1366 | 1359 |
signals.set_signal_handler_to_hang_up()
|
1367 | 1360 |
try:
|
|
1370 | 1363 |
service.connect_container_to_networks(container, use_network_aliases)
|
1371 | 1364 |
exit_code = call_docker(
|
1372 | 1365 |
get_docker_start_call(container_options, container.id),
|
1373 | |
toplevel_options, environment
|
|
1366 |
toplevel_options, toplevel_environment
|
1374 | 1367 |
)
|
1375 | 1368 |
else:
|
1376 | 1369 |
operation = RunOperation(
|