From 2719d3355a29e2ab8d21a93423bfae9f165cb042 Mon Sep 17 00:00:00 2001 From: Mitchell Victoriano Date: Fri, 26 Jul 2024 14:44:19 -0700 Subject: [PATCH] Testing lower level api to see if build prints logs --- workers/src/utility.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/workers/src/utility.py b/workers/src/utility.py index adc8f489..b54c8edf 100644 --- a/workers/src/utility.py +++ b/workers/src/utility.py @@ -1031,23 +1031,34 @@ def create_docker_image( logger_if_able(image, logger) return image else: - logger_if_able("Docker image does not exist") + logger_if_able("Docker image does not exist", logger) + logger_if_able("Creating Docker image", logger) try: # Create docker image from Dockerfile - image, build_logs = client.images.build( + live_log_generator = client.api.build( path=dir_path, tag=tag, rm=True, dockerfile="Dockerfile", buildargs={"zip_file": f"{submission_file_name}"}, ) - for log in build_logs: - if "stream" in log: - logger_if_able(log["stream"].strip()) + for line in live_log_generator: + line_dict = json.loads(line) + if line_dict.get("stream"): + logger_if_able( + line_dict["stream"].rstrip(), logger, "INFO" + ) logger_if_able("Docker image created") + try: + image = client.images.get(tag) + except ImageNotFound: + logger_if_able("Docker image not found", logger) + except Exception as e: + raise e + return image except BuildError as e: logger_if_able(f"Error: {e}", logger, "ERROR")