From 9f1dd284a57bc1b3d0e5d0ec7211e2431f26e054 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 21 Feb 2024 20:12:52 +0000 Subject: [PATCH] Better error logging for registry deployments. (#754) We were missing errors related to registration, this should fix that. Reviewed-on: https://git.vdb.to/cerc-io/stack-orchestrator/pulls/754 Co-authored-by: Thomas E Lackey Co-committed-by: Thomas E Lackey --- .../webapp/deploy_webapp_from_registry.py | 29 +++++++++++-------- stack_orchestrator/deploy/webapp/util.py | 12 ++++++-- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py index 299eeba9..19497749 100644 --- a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py +++ b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py @@ -33,6 +33,7 @@ from stack_orchestrator.deploy.webapp.util import (LaconicRegistryClient, def process_app_deployment_request( + run_id, ctx, laconic: LaconicRegistryClient, app_deployment_request, @@ -42,18 +43,8 @@ def process_app_deployment_request( deployment_parent_dir, kube_config, image_registry, - log_parent_dir + log_file=None ): - run_id = f"{app_deployment_request.id}-{str(time.time()).split('.')[0]}-{str(uuid.uuid4()).split('-')[0]}" - log_file = None - if log_parent_dir: - log_dir = os.path.join(log_parent_dir, app_deployment_request.id) - if not os.path.exists(log_dir): - os.mkdir(log_dir) - log_file_path = os.path.join(log_dir, f"{run_id}.log") - print(f"Directing build logs to: {log_file_path}") - log_file = open(log_file_path, "wt") - # 1. look up application app = laconic.get_record(app_deployment_request.attributes.application, require=True) @@ -291,8 +282,18 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_ for r in requests_to_execute: dump_known_requests(state_file, [r], "DEPLOYING") status = "ERROR" + run_log_file = None try: + run_id = f"{r.id}-{str(time.time()).split('.')[0]}-{str(uuid.uuid4()).split('-')[0]}" + if log_dir: + run_log_dir = os.path.join(log_dir, r.id) + if not os.path.exists(run_log_dir): + os.mkdir(run_log_dir) + run_log_file_path = os.path.join(run_log_dir, f"{run_id}.log") + print(f"Directing deployment logs to: {run_log_file_path}") + run_log_file = open(run_log_file_path, "wt") process_app_deployment_request( + run_id, ctx, laconic, r, @@ -302,8 +303,12 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_ os.path.abspath(deployment_parent_dir), kube_config, image_registry, - log_dir + run_log_file ) status = "DEPLOYED" + except Exception as e: + print("ERROR: " + str(e), file=run_log_file) finally: dump_known_requests(state_file, [r], status) + if run_log_file: + run_log_file.close() diff --git a/stack_orchestrator/deploy/webapp/util.py b/stack_orchestrator/deploy/webapp/util.py index 80b477f9..e6fd9ffe 100644 --- a/stack_orchestrator/deploy/webapp/util.py +++ b/stack_orchestrator/deploy/webapp/util.py @@ -227,8 +227,16 @@ def build_container_image(app_record, tag, extra_build_args=[], log_file=None): git_env = dict(os.environ.copy()) # Never prompt git_env["GIT_TERMINAL_PROMPT"] = "0" - subprocess.check_call(["git", "clone", repo, clone_dir], env=git_env, stdout=log_file, stderr=log_file) - subprocess.check_call(["git", "checkout", ref], cwd=clone_dir, env=git_env, stdout=log_file, stderr=log_file) + try: + subprocess.check_call(["git", "clone", repo, clone_dir], env=git_env, stdout=log_file, stderr=log_file) + except Exception as e: + print(f"git clone failed. Is the repository {repo} private?", file=log_file) + raise e + try: + subprocess.check_call(["git", "checkout", ref], cwd=clone_dir, env=git_env, stdout=log_file, stderr=log_file) + except Exception as e: + print(f"git checkout failed. Does ref {ref} exist?", file=log_file) + raise e else: result = subprocess.run(["git", "clone", "--depth", "1", repo, clone_dir], stdout=log_file, stderr=log_file) result.check_returncode()