Skip to content

Commit 88fa830

Browse files
committed
Return logs to the platform, check current container
1 parent 1e5ebb9 commit 88fa830

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

compute_worker/compute_worker.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,15 @@ def check_docker_image_update():
317317
tag=Settings.DOCKER_IMAGE_TAG,
318318
docker_base_url=Settings.CONTAINER_SOCKET
319319
)
320-
result = checker.compare_local_vs_remote_images()
320+
result = checker.compare_local_vs_remote_images(container_id=socket.gethostname())
321321
status = result["status"]
322322

323323
log_level = logging.INFO
324324

325325
log_lines = [
326326
"",
327327
"=" * 60,
328-
"DOCKER IMAGE UPDATE CHECK",
328+
"COMPUTE WORKER DOCKER IMAGE UPDATE CHECK",
329329
"=" * 60,
330330
f"Image: {result.get('image_name')}",
331331
]
@@ -350,7 +350,7 @@ def check_docker_image_update():
350350
log_level = logging.ERROR
351351

352352
elif status == DockerImageStatus.LOCAL_MISSING:
353-
log_lines.append("Status: Local image is not present. Pull required")
353+
log_lines.append("Status: Local image not found. Pull required")
354354
log_level = logging.ERROR
355355

356356
elif status == DockerImageStatus.REMOTE_UNAVAILABLE:
@@ -368,6 +368,10 @@ def check_docker_image_update():
368368

369369
logger.log(log_level, "\n".join(log_lines))
370370

371+
if status != DockerImageStatus.UP_TO_DATE:
372+
return "\n".join(log_lines) + "\n"
373+
return None
374+
371375

372376
# -----------------------------------------------------------------------------
373377
# The main compute worker entrypoint, this is how a job is ran at the highest
@@ -376,12 +380,14 @@ def check_docker_image_update():
376380
@shared_task(name="compute_worker_run")
377381
def run_wrapper(run_args):
378382
# Check for docker image update
379-
check_docker_image_update()
383+
docker_image_warning = check_docker_image_update()
380384

381385
# We need to convert the UUID given by celery into a byte like object otherwise things will break
382386
run_args.update(secret=str(run_args["secret"]))
383387
logger.info(f"Received run arguments: \n {colorize_run_args(json.dumps(run_args))}")
384388
run = Run(run_args)
389+
if docker_image_warning:
390+
run.docker_image_warning = docker_image_warning.encode()
385391
try:
386392
run.prepare()
387393
run.start()
@@ -531,6 +537,7 @@ def __init__(self, run_args):
531537
self.output_dir = os.path.join(self.root_dir, "output")
532538
self.data_dir = os.path.join(Settings.HOST_DIRECTORY, "data") # absolute path to data in the host
533539
self.logs = {}
540+
self.docker_image_warning = None
534541

535542
# Details for submission
536543
self.is_scoring = run_args["is_scoring"]
@@ -626,6 +633,8 @@ def push_logs(self):
626633
continue
627634
location = entry.get("location")
628635
data = entry.get("data") or b""
636+
if self.docker_image_warning and stream_key == "stderr":
637+
data = self.docker_image_warning + data
629638
if location:
630639
self._put_file(location, raw_data=data)
631640
except Exception as e:

compute_worker/docker_image_update_checker.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,17 @@ def get_remote_info(self):
5151
),
5252
}
5353

54-
def get_local_info(self):
54+
def get_local_info(self, container_id=None):
5555
try:
56-
image = self.client.inspect_image(self.image_name)
56+
if container_id:
57+
try:
58+
container = self.client.inspect_container(container_id)
59+
image = self.client.inspect_image(container["Image"])
60+
except docker.errors.DockerException:
61+
# container_id could not be resolved, fall back to image name
62+
image = self.client.inspect_image(self.image_name)
63+
else:
64+
image = self.client.inspect_image(self.image_name)
5765
return {
5866
"id": image.get("Id"),
5967
"digests": image.get("RepoDigests", []),
@@ -83,11 +91,11 @@ def _get_status(self, remote: dict, local: dict):
8391

8492
return DockerImageStatus.DIFFERENT
8593

86-
def compare_local_vs_remote_images(self):
94+
def compare_local_vs_remote_images(self, container_id=None):
8795

8896
try:
8997
remote = self.get_remote_info()
90-
local = self.get_local_info()
98+
local = self.get_local_info(container_id=container_id)
9199

92100
if not remote:
93101
return {

0 commit comments

Comments
 (0)