Skip to content

Commit 37774fc

Browse files
authored
Merge pull request #727 from minrk/full-progress
include full docker progress events in push progress events
2 parents 82cd28d + 6385097 commit 37774fc

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

repo2docker/app.py

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -453,24 +453,39 @@ def push_image(self):
453453
client = docker.APIClient(version="auto", **kwargs_from_env())
454454
# Build a progress setup for each layer, and only emit per-layer
455455
# info every 1.5s
456+
progress_layers = {}
456457
layers = {}
457458
last_emit_time = time.time()
458-
for line in client.push(self.output_image_spec, stream=True):
459-
progress = json.loads(line.decode("utf-8"))
460-
if "error" in progress:
461-
self.log.error(progress["error"], extra=dict(phase="failed"))
462-
raise docker.errors.ImageLoadError(progress["error"])
463-
if "id" not in progress:
464-
continue
465-
if "progressDetail" in progress and progress["progressDetail"]:
466-
layers[progress["id"]] = progress["progressDetail"]
467-
else:
468-
layers[progress["id"]] = progress["status"]
469-
if time.time() - last_emit_time > 1.5:
470-
self.log.info(
471-
"Pushing image\n", extra=dict(progress=layers, phase="pushing")
472-
)
473-
last_emit_time = time.time()
459+
for chunk in client.push(self.output_image_spec, stream=True):
460+
# each chunk can be one or more lines of json events
461+
# split lines here in case multiple are delivered at once
462+
for line in chunk.splitlines():
463+
line = line.decode("utf-8", errors="replace")
464+
try:
465+
progress = json.loads(line)
466+
except Exception as e:
467+
self.log.warning("Not a JSON progress line: %r", line)
468+
continue
469+
if "error" in progress:
470+
self.log.error(progress["error"], extra=dict(phase="failed"))
471+
raise docker.errors.ImageLoadError(progress["error"])
472+
if "id" not in progress:
473+
continue
474+
# deprecated truncated-progress data
475+
if "progressDetail" in progress and progress["progressDetail"]:
476+
progress_layers[progress["id"]] = progress["progressDetail"]
477+
else:
478+
progress_layers[progress["id"]] = progress["status"]
479+
# include full progress data for each layer in 'layers' data
480+
layers[progress["id"]] = progress
481+
if time.time() - last_emit_time > 1.5:
482+
self.log.info(
483+
"Pushing image\n",
484+
extra=dict(
485+
progress=progress_layers, layers=layers, phase="pushing"
486+
),
487+
)
488+
last_emit_time = time.time()
474489
self.log.info(
475490
"Successfully pushed {}".format(self.output_image_spec),
476491
extra=dict(phase="pushing"),

0 commit comments

Comments
 (0)