From bb39d90522721a7cdd3bea9b39a8737c736133f9 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Fri, 17 Feb 2023 15:31:43 -0700 Subject: [PATCH] Add pre/post script support --- app/deploy_system.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/deploy_system.py b/app/deploy_system.py index 91ffa28c..29028a53 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -124,10 +124,10 @@ def command(ctx, include, exclude, cluster, command, extra_args): if verbose: print(f"Running compose up for extra_args: {extra_args_list}") for pre_start_command in pre_start_commands: - _run_command(ctx.obj, pre_start_command) + _run_command(ctx.obj, cluster, pre_start_command) docker.compose.up(detach=True, services=extra_args_list) for post_start_command in post_start_commands: - _run_command(ctx.obj, post_start_command) + _run_command(ctx.obj, cluster, post_start_command) elif command == "down": if verbose: print("Running compose down") @@ -196,14 +196,17 @@ def _convert_to_new_format(old_pod_array): return new_pod_array -def _run_command(ctx, command): +def _run_command(ctx, cluster_name, command): if ctx.verbose: print(f"Running command: {command}") command_dir = os.path.dirname(command) print(f"command_dir: {command_dir}") command_file = os.path.join(".", os.path.basename(command)) - my_env = os.environ.copy() - command_result = subprocess.run(f"bash {command_file}", shell=True, env=my_env, cwd=command_dir) + command_env = os.environ.copy() + command_env["CERC_SO_COMPOSE_PROJECT"] = cluster_name + if ctx.debug: + command_env["CERC_SCRIPT_DEBUG"] = "true" + command_result = subprocess.run(command_file, shell=True, env=command_env, cwd=command_dir) if command_result.returncode != 0: print(f"FATAL Error running command: {command}") sys.exit(1)