Codebase list docker-compose / 7a7c9ff
Merge pull request #6800 from KlaasH/revise-env-file-option Make '--env-file' option top-level only and fix failure with subcommands Djordje Lukic authored 4 years ago GitHub committed 4 years ago
5 changed file(s) with 26 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
246246 def project_dir(self):
247247 return self.toplevel_options.get('--project-directory') or '.'
248248
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
249254 def build(self, options):
250255 """
251256 Build or rebuild services.
275280 '--build-arg is only supported when services are specified for API version < 1.25.'
276281 ' Please use a Compose file version > 2.2 or specify which services to build.'
277282 )
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)
281284
282285 self.project.build(
283286 service_names=options['SERVICE'],
428431 Compose file
429432 -t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
430433 (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')
436436
437437 if ignore_orphans and options['--remove-orphans']:
438438 raise UserError("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined.")
488488 -e, --env KEY=VAL Set environment variables (can be used multiple times,
489489 not supported in API < 1.25)
490490 -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')
496493 index = int(options.get('--index'))
497494 service = self.project.get_service(options['SERVICE'])
498495 detach = options.get('--detach')
515512 if IS_WINDOWS_PLATFORM or use_cli and not detach:
516513 sys.exit(call_docker(
517514 build_exec_command(options, container.id, command),
518 self.toplevel_options, environment)
515 self.toplevel_options, self.toplevel_environment)
519516 )
520517
521518 create_exec_options = {
889886 container_options = build_one_off_container_options(options, detach, command)
890887 run_one_off_container(
891888 container_options, self.project, service, options,
892 self.toplevel_options, self.project_dir
889 self.toplevel_options, self.toplevel_environment
893890 )
894891
895892 def scale(self, options):
10501047 container. Implies --abort-on-container-exit.
10511048 --scale SERVICE=NUM Scale SERVICE to NUM instances. Overrides the
10521049 `scale` setting in the Compose file if present.
1053 --env-file PATH Specify an alternate environment file
10541050 """
10551051 start_deps = not options['--no-deps']
10561052 always_recreate_deps = options['--always-recreate-deps']
10651061 if detached and (cascade_stop or exit_value_from):
10661062 raise UserError("--abort-on-container-exit and -d cannot be combined.")
10671063
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')
10711065
10721066 if ignore_orphans and remove_orphans:
10731067 raise UserError("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined.")
13301324
13311325
13321326 def run_one_off_container(container_options, project, service, options, toplevel_options,
1333 project_dir='.'):
1327 toplevel_environment):
13341328 if not options['--no-deps']:
13351329 deps = service.get_dependency_names()
13361330 if deps:
13591353 if options['--rm']:
13601354 project.client.remove_container(container.id, force=True, v=True)
13611355
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
13651358 signals.set_signal_handler_to_shutdown()
13661359 signals.set_signal_handler_to_hang_up()
13671360 try:
13701363 service.connect_container_to_networks(container, use_network_aliases)
13711364 exit_code = call_docker(
13721365 get_docker_start_call(container_options, container.id),
1373 toplevel_options, environment
1366 toplevel_options, toplevel_environment
13741367 )
13751368 else:
13761369 operation = RunOperation(
2525 key = env
2626 if re.search(r'\s', key):
2727 raise ConfigurationError(
28 "environment variable name '{}' may not contains whitespace.".format(key)
28 "environment variable name '{}' may not contain whitespace.".format(key)
2929 )
3030 return key, value
3131
181181 ;;
182182 --project-directory)
183183 _filedir -d
184 return
185 ;;
186 --env-file)
187 _filedir
184188 return
185189 ;;
186190 $(__docker_compose_to_extglob "$daemon_options_with_args") )
611615 --tlsverify
612616 "
613617 local daemon_options_with_args="
618 --env-file
614619 --file -f
615620 --host -H
616621 --project-directory
1111
1212 complete -c docker-compose -s f -l file -r -d 'Specify an alternate compose file'
1313 complete -c docker-compose -s p -l project-name -x -d 'Specify an alternate project name'
14 complete -c docker-compose -l env-file -r -d 'Specify an alternate environment file (default: .env)'
1415 complete -c docker-compose -l verbose -d 'Show more output'
1516 complete -c docker-compose -s H -l host -x -d 'Daemon socket to connect to'
1617 complete -c docker-compose -l tls -d 'Use TLS; implied by --tlsverify'
340340 '(- :)'{-h,--help}'[Get help]' \
341341 '*'{-f,--file}"[${file_description}]:file:_files -g '*.yml'" \
342342 '(-p --project-name)'{-p,--project-name}'[Specify an alternate project name (default: directory name)]:project name:' \
343 '--env-file[Specify an alternate environment file (default: .env)]:env-file:_files' \
343344 "--compatibility[If set, Compose will attempt to convert keys in v3 files to their non-Swarm equivalent]" \
344345 '(- :)'{-v,--version}'[Print version and exit]' \
345346 '--verbose[Show more output]' \
358359 local -a relevant_compose_flags relevant_compose_repeatable_flags relevant_docker_flags compose_options docker_options
359360
360361 relevant_compose_flags=(
362 "--env-file"
361363 "--file" "-f"
362364 "--host" "-H"
363365 "--project-name" "-p"