16
16
import shutil
17
17
import tempfile
18
18
import time
19
-
20
- from .engine import BuildError , ContainerEngineException , ImageLoadError
21
19
from urllib .parse import urlparse
20
+
22
21
import escapism
22
+ from iso8601 import parse_date
23
23
from pythonjsonlogger import jsonlogger
24
24
25
25
from traitlets import Any , Dict , Int , List , Unicode , Bool , default
38
38
RBuildPack ,
39
39
)
40
40
from . import contentproviders
41
+ from .engine import BuildError , ContainerEngineException , ImageLoadError
41
42
from .utils import ByteSpecification , chdir
42
43
43
44
@@ -629,9 +630,12 @@ def wait_for_container(self, container):
629
630
Displaying logs while it's running
630
631
"""
631
632
633
+ last_timestamp = None
632
634
try :
633
- for line in container .logs (stream = True ):
634
- self .log .info (line .decode ("utf-8" ), extra = dict (phase = "running" ))
635
+ for line in container .logs (stream = True , timestamps = True ):
636
+ line = line .decode ("utf-8" )
637
+ last_timestamp , line = line .split (" " , maxsplit = 1 )
638
+ self .log .info (line , extra = dict (phase = "running" ))
635
639
636
640
finally :
637
641
container .reload ()
@@ -646,9 +650,16 @@ def wait_for_container(self, container):
646
650
"Container finished running.\n " .upper (), extra = dict (phase = "running" )
647
651
)
648
652
# are there more logs? Let's send them back too
649
- late_logs = container .logs ().decode ("utf-8" )
653
+ if last_timestamp :
654
+ # docker only accepts integer timestamps
655
+ # this means we will usually replay logs from the last second
656
+ # of the container
657
+ # we should check if this ever returns anything new,
658
+ # since we know it ~always returns something redundant
659
+ last_timestamp = int (parse_date (last_timestamp ).timestamp ())
660
+ late_logs = container .logs (since = last_timestamp ).decode ("utf-8" )
650
661
for line in late_logs .split ("\n " ):
651
- self .log .info (line + "\n " , extra = dict (phase = "running" ))
662
+ self .log .debug (line + "\n " , extra = dict (phase = "running" ))
652
663
653
664
container .remove ()
654
665
if exit_code :
0 commit comments