Skip to content

Commit

Permalink
Testing lower level api to see if build prints logs
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellAV committed Jul 26, 2024
1 parent 26a1504 commit 2719d33
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions workers/src/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 2719d33

Please sign in to comment.