diff --git a/app/deploy_system.py b/app/deploy_system.py index f7bf71b1..91ffa28c 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -19,6 +19,7 @@ import hashlib import os import sys from decouple import config +import subprocess from python_on_whales import DockerClient import click import importlib.resources @@ -123,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: - 1 + _run_command(ctx.obj, pre_start_command) docker.compose.up(detach=True, services=extra_args_list) for post_start_command in post_start_commands: - 1 + _run_command(ctx.obj, post_start_command) elif command == "down": if verbose: print("Running compose down") @@ -193,3 +194,16 @@ def _convert_to_new_format(old_pod_array): } new_pod_array.append(new_pod) return new_pod_array + + +def _run_command(ctx, 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) + if command_result.returncode != 0: + print(f"FATAL Error running command: {command}") + sys.exit(1)