From 912483df585b423c5585b1d908396dc0132bf909 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Fri, 17 Feb 2023 14:15:35 -0700 Subject: [PATCH] Basic functionality Former-commit-id: a1893aa153bec36426d3d1f294040f31cadbe8cf --- app/deploy_system.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/deploy_system.py b/app/deploy_system.py index f7bf71b..91ffa28 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)