Skip to content

Commit 19e0255

Browse files
committed
include full docker progress data in push events
Most useful is probably progressDetail.progress which is the docker rendered Example event: ```json "layers": { "25b373f5f7f1": { "status": "Waiting", "progressDetail": {}, "id": "25b373f5f7f1" }, "e9f2b5eca21e": { "status": "Pushing", "progressDetail": { "current": 747589632, "total": 758965327 }, "progress": "[=================================================> ] 747.6MB/759MB", "id": "e9f2b5eca21e" }, "7753d7e0913b": { "status": "Pushed", "progressDetail": {}, "id": "7753d7e0913b" }, "ed03b06eb165": { "status": "Pushed", "progressDetail": {}, "id": "ed03b06eb165" }, "01cb88e6c1af": { "status": "Pushed", "progressDetail": {}, "id": "01cb88e6c1af" }, "adda4de99b3d": { "status": "Mounted from library/buildpack-deps", "progressDetail": {}, "id": "adda4de99b3d" }, "3a034154b7b6": { "status": "Mounted from library/buildpack-deps", "progressDetail": {}, "id": "3a034154b7b6" } ```
1 parent 4b0e838 commit 19e0255

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

repo2docker/app.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -453,24 +453,38 @@ 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+
for line in chunk.splitlines():
461+
line = line.decode("utf-8", errors="replace")
462+
try:
463+
progress = json.loads(line)
464+
except Exception as e:
465+
self.log.warning("Not a JSON progress line: %r", line)
466+
continue
467+
if "error" in progress:
468+
self.log.error(progress["error"], extra=dict(phase="failed"))
469+
raise docker.errors.ImageLoadError(progress["error"])
470+
if "id" not in progress:
471+
continue
472+
# deprecated truncated-progress data
473+
if "progressDetail" in progress and progress["progressDetail"]:
474+
progress_layers[progress["id"]] = progress["progressDetail"]
475+
else:
476+
progress_layers[progress["id"]] = progress["status"]
477+
# include full progress data for each layer in 'layers' data
478+
layers[progress["id"]] = progress
479+
if time.time() - last_emit_time > 1.5:
480+
self.log.info(
481+
"Pushing image\n", extra=dict(
482+
progress=progress_layers,
483+
layers=layers,
484+
phase="pushing",
485+
)
486+
)
487+
last_emit_time = time.time()
474488
self.log.info(
475489
"Successfully pushed {}".format(self.output_image_spec),
476490
extra=dict(phase="pushing"),

0 commit comments

Comments
 (0)