From be6a47377238596ad3c3f615d62d652be7c358a0 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Thu, 2 Mar 2023 10:53:48 -0700 Subject: [PATCH] Pass environment variables for both exec and up --- app/deploy_system.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/deploy_system.py b/app/deploy_system.py index d90f042f..2d58967e 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -56,10 +56,11 @@ def command(ctx, include, exclude, cluster, command, extra_args): if not dry_run: if command == "up": - if debug: - os.environ["CERC_SCRIPT_DEBUG"] = "true" + container_exec_env = _make_runtime_env(ctx.obj) + for attr, value in container_exec_env.items(): + os.environ[attr] = value if verbose: - print(f"Running compose up for extra_args: {extra_args_list}") + print(f"Running compose up with container_exec_env: {container_exec_env}, extra_args: {extra_args_list}") for pre_start_command in cluster_context.pre_start_commands: _run_command(ctx.obj, cluster_context.cluster, pre_start_command) docker.compose.up(detach=True, services=extra_args_list) @@ -75,11 +76,7 @@ def command(ctx, include, exclude, cluster, command, extra_args): sys.exit(1) service_name = extra_args_list[0] command_to_exec = extra_args_list[1:] - container_exec_env = { - "CERC_HOST_UID": f"{os.getuid()}", - "CERC_HOST_GID": f"{os.getgid()}" - } - container_exec_env.update({"CERC_SCRIPT_DEBUG": "true"} if debug else {}) + container_exec_env = _make_runtime_env(ctx.obj) if verbose: print(f"Running compose exec {service_name} {command_to_exec}") docker.compose.execute(service_name, command_to_exec, envs=container_exec_env) @@ -141,6 +138,15 @@ def get_stack_status(ctx, stack): False +def _make_runtime_env(ctx): + container_exec_env = { + "CERC_HOST_UID": f"{os.getuid()}", + "CERC_HOST_GID": f"{os.getgid()}" + } + container_exec_env.update({"CERC_SCRIPT_DEBUG": "true"} if ctx.debug else {}) + return container_exec_env + + def _make_cluster_context(ctx, include, exclude, cluster): if ctx.local_stack: