@@ -340,11 +340,16 @@ def cleanup(self):
340340 print (
341341 f'Unable to find docker container with name or label "{ container } "'
342342 )
343- self .docker_client .remove_container (
344- self .container ["Id" ],
345- force = True ,
346- v = True ,
347- )
343+ try :
344+ self .docker_client .remove_container (
345+ self .container ["Id" ],
346+ force = True ,
347+ v = True ,
348+ )
349+ except docker .errors .NotFound :
350+ print (
351+ f'Unable to find docker container with id "{ self .container ["Id" ]} "'
352+ )
348353
349354 self .container = None
350355
@@ -353,16 +358,16 @@ def _get_cache_file_from_prefix(
353358 logger : ContainerLogger , local_cache_archive_file : str , docker_path : str
354359 ) -> Optional [str ]:
355360 if os .path .exists (local_cache_archive_file ):
356- logger .write (
357- f"Using cache { local_cache_archive_file } for destination path { docker_path } \n "
361+ logger .info (
362+ f"Using cache { local_cache_archive_file } for destination path { docker_path } "
358363 )
359364 return local_cache_archive_file
360365 cache_dir = os .path .dirname (local_cache_archive_file )
361366
362367 if not os .path .exists (cache_dir ):
363- logger .write (
368+ logger .info (
364369 f"Cache directory { cache_dir } does not exist, "
365- f"skipping restore of archive { local_cache_archive_file } \n "
370+ f"skipping restore of archive { local_cache_archive_file } "
366371 )
367372 return None
368373
@@ -381,14 +386,14 @@ def _get_cache_file_from_prefix(
381386 local_cache_archive_match = curr_archive_file
382387
383388 if local_cache_archive_match is None :
384- logger .write (
389+ logger .info (
385390 f"Not able to restore cache { docker_path } since "
386- f"there was no matching prefix for `{ local_cache_archive_file } `\n "
391+ f"there was no matching prefix for `{ local_cache_archive_file } `"
387392 )
388393 return None
389- logger .write (
394+ logger .info (
390395 f"Found cache { local_cache_archive_match } matching prefix { local_cache_archive_file } "
391- f"for destination path { docker_path } \n "
396+ f"for destination path { docker_path } "
392397 )
393398
394399 return local_cache_archive_match
@@ -422,9 +427,9 @@ def restore_caches(self, logger: ContainerLogger, caches: OrderedDict) -> None:
422427 restored_cache_src = set ()
423428 for local_cache_archive_file , docker_path in caches .items ():
424429 if docker_path in restored_cache_src :
425- logger .write (
430+ logger .info (
426431 f"Cache for destination path { docker_path } has already been matched and restored to the container, "
427- f"skipping { local_cache_archive_file } \n "
432+ f"skipping { local_cache_archive_file } "
428433 )
429434 continue
430435
@@ -507,13 +512,13 @@ def write_cache_history_log(
507512 file_obj = acquire_flock_open_write_binary (
508513 lock_file = cache_history_log , logger = logger , mode = "a"
509514 )
510- logger .write (
515+ logger .info (
511516 f"File lock acquired. Attempting to write cache history log to { cache_history_log } "
512517 )
513518 file_obj .write (log_str )
514519 finally :
515520 release_flock (file_obj , logger )
516- logger .write ("Writing to cache history log completed. Released file lock. " )
521+ logger .info ("Writing to cache history log completed, released file lock" )
517522
518523 def save_caches (
519524 self , logger : ContainerLogger , caches : OrderedDict , env_vars : dict = dict ()
@@ -526,10 +531,10 @@ def save_caches(
526531 for local_cache_archive_file , docker_path in caches .items ():
527532 if docker_path not in saved_cache_src :
528533 saved_cache_src .add (docker_path )
529- logger .write (
530- f"Saving cache ` { docker_path } ` "
534+ logger .info (
535+ f"Saving cache { docker_path } "
531536 f"running on container { self .container ['Id' ]} "
532- f"to local cache ` { local_cache_archive_file } ` \n "
537+ f"to local cache { local_cache_archive_file } "
533538 )
534539
535540 log_line = (
@@ -551,9 +556,7 @@ def save_caches(
551556 file_obj = acquire_flock_open_write_binary (
552557 lock_file = local_cache_archive_file , logger = logger
553558 )
554- logger .write (
555- "File lock acquired. Attempting to write to cache."
556- )
559+ logger .info ("File lock acquired. Attempting to write to cache." )
557560 self ._write_cache (docker_path , file_obj )
558561 except Exception as e :
559562 raise BuildRunnerSavingCache (
@@ -564,11 +567,11 @@ def save_caches(
564567 assert tarfile .is_tarfile (
565568 local_cache_archive_file
566569 ), f"Failed to create cache { local_cache_archive_file } tar file."
567- logger .write ("Writing to cache completed. Released file lock." )
570+ logger .info ("Writing to cache completed. Released file lock." )
568571 else :
569- logger .write (
572+ logger .info (
570573 f"The following `{ docker_path } ` in docker has already been saved. "
571- f"It will not be saved again to `{ local_cache_archive_file } `\n "
574+ f"It will not be saved again to `{ local_cache_archive_file } `"
572575 )
573576
574577 def run (self , cmd , console = None , stream = True , log = None , workdir = None ):
0 commit comments