3838)
3939from . import contentproviders
4040from .engine import BuildError , ContainerEngineException , ImageLoadError
41- from .utils import ByteSpecification , chdir
41+ from .utils import ByteSpecification , chdir , R2dState
4242
4343
4444class Repo2Docker (Application ):
@@ -465,7 +465,7 @@ def fetch(self, url, ref, checkout_path):
465465 for log_line in picked_content_provider .fetch (
466466 spec , checkout_path , yield_output = self .json_logs
467467 ):
468- self .log .info (log_line , extra = dict (phase = "fetching" ))
468+ self .log .info (log_line , extra = dict (phase = R2dState . FETCHING ))
469469
470470 if not self .output_image_spec :
471471 image_spec = "r2d" + self .repo
@@ -491,7 +491,7 @@ def json_excepthook(self, etype, evalue, traceback):
491491 "Error during build: %s" ,
492492 evalue ,
493493 exc_info = (etype , evalue , traceback ),
494- extra = dict (phase = "failed" ),
494+ extra = dict (phase = R2dState . FAILED ),
495495 )
496496
497497 def initialize (self , * args , ** kwargs ):
@@ -532,7 +532,7 @@ def push_image(self):
532532 last_emit_time = time .time ()
533533 for chunk in client .push (self .output_image_spec ):
534534 if client .string_output :
535- self .log .info (chunk , extra = dict (phase = "pushing" ))
535+ self .log .info (chunk , extra = dict (phase = R2dState . PUSHING ))
536536 continue
537537 # else this is Docker output
538538
@@ -546,7 +546,7 @@ def push_image(self):
546546 self .log .warning ("Not a JSON progress line: %r" , line )
547547 continue
548548 if "error" in progress :
549- self .log .error (progress ["error" ], extra = dict (phase = "failed" ))
549+ self .log .error (progress ["error" ], extra = dict (phase = R2dState . FAILED ))
550550 raise ImageLoadError (progress ["error" ])
551551 if "id" not in progress :
552552 continue
@@ -561,13 +561,15 @@ def push_image(self):
561561 self .log .info (
562562 "Pushing image\n " ,
563563 extra = dict (
564- progress = progress_layers , layers = layers , phase = "pushing"
564+ progress = progress_layers ,
565+ layers = layers ,
566+ phase = R2dState .PUSHING ,
565567 ),
566568 )
567569 last_emit_time = time .time ()
568570 self .log .info (
569571 "Successfully pushed {}" .format (self .output_image_spec ),
570- extra = dict (phase = "pushing" ),
572+ extra = dict (phase = R2dState . PUSHING ),
571573 )
572574
573575 def run_image (self ):
@@ -659,24 +661,27 @@ def wait_for_container(self, container):
659661 for line in container .logs (stream = True , timestamps = True ):
660662 line = line .decode ("utf-8" )
661663 last_timestamp , line = line .split (" " , maxsplit = 1 )
662- self .log .info (line , extra = dict (phase = "running" ))
664+ self .log .info (line , extra = dict (phase = R2dState . RUNNING ))
663665
664666 finally :
665667 container .reload ()
666668 if container .status == "running" :
667- self .log .info ("Stopping container...\n " , extra = dict (phase = "running" ))
669+ self .log .info (
670+ "Stopping container...\n " , extra = dict (phase = R2dState .RUNNING )
671+ )
668672 container .kill ()
669673 exit_code = container .exitcode
670674
671675 container .wait ()
672676
673677 self .log .info (
674- "Container finished running.\n " .upper (), extra = dict (phase = "running" )
678+ "Container finished running.\n " .upper (),
679+ extra = dict (phase = R2dState .RUNNING ),
675680 )
676681 # are there more logs? Let's send them back too
677682 late_logs = container .logs (since = last_timestamp ).decode ("utf-8" )
678683 for line in late_logs .split ("\n " ):
679- self .log .debug (line + "\n " , extra = dict (phase = "running" ))
684+ self .log .debug (line + "\n " , extra = dict (phase = R2dState . RUNNING ))
680685
681686 container .remove ()
682687 if exit_code :
@@ -751,7 +756,7 @@ def build(self):
751756 self .log .error (
752757 "Subdirectory %s does not exist" ,
753758 self .subdir ,
754- extra = dict (phase = "failure" ),
759+ extra = dict (phase = R2dState . FAILED ),
755760 )
756761 raise FileNotFoundError ("Could not find {}" .format (checkout_path ))
757762
@@ -786,7 +791,7 @@ def build(self):
786791 else :
787792 self .log .debug (
788793 picked_buildpack .render (build_args ),
789- extra = dict (phase = "building" ),
794+ extra = dict (phase = R2dState . BUILDING ),
790795 )
791796 if self .user_id == 0 :
792797 raise ValueError (
@@ -796,7 +801,7 @@ def build(self):
796801 self .log .info (
797802 "Using %s builder\n " ,
798803 bp .__class__ .__name__ ,
799- extra = dict (phase = "building" ),
804+ extra = dict (phase = R2dState . BUILDING ),
800805 )
801806
802807 for l in picked_buildpack .build (
@@ -808,19 +813,24 @@ def build(self):
808813 self .extra_build_kwargs ,
809814 ):
810815 if docker_client .string_output :
811- self .log .info (l , extra = dict (phase = "building" ))
816+ self .log .info (l , extra = dict (phase = R2dState . BUILDING ))
812817 # else this is Docker output
813818 elif "stream" in l :
814- self .log .info (l ["stream" ], extra = dict (phase = "building" ))
819+ self .log .info (
820+ l ["stream" ], extra = dict (phase = R2dState .BUILDING )
821+ )
815822 elif "error" in l :
816- self .log .info (l ["error" ], extra = dict (phase = "failure" ))
823+ self .log .info (l ["error" ], extra = dict (phase = R2dState . FAILED ))
817824 raise BuildError (l ["error" ])
818825 elif "status" in l :
819826 self .log .info (
820- "Fetching base image...\r " , extra = dict (phase = "building" )
827+ "Fetching base image...\r " ,
828+ extra = dict (phase = R2dState .BUILDING ),
821829 )
822830 else :
823- self .log .info (json .dumps (l ), extra = dict (phase = "building" ))
831+ self .log .info (
832+ json .dumps (l ), extra = dict (phase = R2dState .BUILDING )
833+ )
824834
825835 finally :
826836 # Cleanup checkout if necessary
0 commit comments