From ab1e33bc4ce5747e36fb48dfd7d1b19d0493bfa6 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 9 Jul 2021 10:24:09 +0200 Subject: [PATCH] move docker timestamp-parsing quirk to docker itself our Container API can be more sensible and symmetrical than docker itself --- repo2docker/app.py | 8 -------- repo2docker/docker.py | 9 +++++++++ repo2docker/engine.py | 8 +++++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/repo2docker/app.py b/repo2docker/app.py index 7cce2c00..94671373 100755 --- a/repo2docker/app.py +++ b/repo2docker/app.py @@ -19,7 +19,6 @@ import time from urllib.parse import urlparse import escapism -from iso8601 import parse_date from pythonjsonlogger import jsonlogger from traitlets import Any, Dict, Int, List, Unicode, Bool, default @@ -650,13 +649,6 @@ class Repo2Docker(Application): "Container finished running.\n".upper(), extra=dict(phase="running") ) # are there more logs? Let's send them back too - if last_timestamp: - # docker only accepts integer timestamps - # this means we will usually replay logs from the last second - # of the container - # we should check if this ever returns anything new, - # since we know it ~always returns something redundant - last_timestamp = int(parse_date(last_timestamp).timestamp()) late_logs = container.logs(since=last_timestamp).decode("utf-8") for line in late_logs.split("\n"): self.log.debug(line + "\n", extra=dict(phase="running")) diff --git a/repo2docker/docker.py b/repo2docker/docker.py index 8c622fe3..c1f3b418 100644 --- a/repo2docker/docker.py +++ b/repo2docker/docker.py @@ -3,6 +3,8 @@ Docker container engine for repo2docker """ import docker +from iso8601 import parse_date + from .engine import Container, ContainerEngine, ContainerEngineException, Image @@ -14,6 +16,13 @@ class DockerContainer(Container): return self._c.reload() def logs(self, *, stream=False, timestamps=False, since=None): + if since: + # docker only accepts integer timestamps + # this means we will usually replay logs from the last second + # of the container + # we should check if this ever returns anything new, + # since we know it ~always returns something redundant + since = int(parse_date(since).timestamp()) return self._c.logs(stream=stream, timestamps=timestamps, since=since) def kill(self, *, signal="KILL"): diff --git a/repo2docker/engine.py b/repo2docker/engine.py index 2ab708bc..4b2a6201 100644 --- a/repo2docker/engine.py +++ b/repo2docker/engine.py @@ -31,9 +31,11 @@ class Container(ABC): If `True` return an iterator over the log lines, otherwise return all logs timestamps : bool If `True` log lines will be prefixed with iso8601 timestamps followed by space - since : int - An integer timestamp. - Can be constructed by parsing timestamps in prefixed lines issued when `timestamps=True`. + since : str + A timestamp string + Should be in the same format as the timestamp prefix given + when `timestamps=True` + If given, start logs from this point, instead of from container start.