Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit d9f4eec

Browse files
authored
added progress bar (#195)
1 parent a9427d1 commit d9f4eec

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ jinja2==2.11.2
44
PyYAML==5.3.1
55
black==19.10b0
66
mypy==0.782
7+
tqdm==v4.49.0

scripts/dev/dockerutil.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dockerfile_generator import render
33
import os
44
import json
5+
from tqdm import tqdm
56

67
from typing import Union, Any, Optional
78

@@ -23,9 +24,13 @@ def push_image(tag: str) -> None:
2324
"""
2425
client = docker.from_env()
2526
print(f"Pushing image: {tag}")
26-
progress = ""
27-
for line in client.images.push(tag, stream=True):
28-
print("\r" + push_image_formatted(line), end="", flush=True)
27+
with tqdm(total=100, ascii=False) as progress_bar:
28+
last_percent = 0.0
29+
for line in client.images.push(tag, stream=True):
30+
percent = get_completion_percentage(line)
31+
if percent:
32+
progress_bar.update(percent - last_percent)
33+
last_percent = percent
2934

3035

3136
def retag_image(
@@ -64,28 +69,27 @@ def retag_image(
6469
client.images.push(new_repo_url, new_tag)
6570

6671

67-
def push_image_formatted(line: Any) -> str:
72+
def get_completion_percentage(line: Any) -> float:
6873
try:
6974
line = json.loads(line.strip().decode("utf-8"))
7075
except ValueError:
71-
return ""
76+
return 0
7277

7378
to_skip = ("Preparing", "Waiting", "Layer already exists")
7479
if "status" in line:
7580
if line["status"] in to_skip:
76-
return ""
81+
return 0
7782
if line["status"] == "Pushing":
7883
try:
79-
current = int(line["progressDetail"]["current"])
80-
total = int(line["progressDetail"]["total"])
84+
current = float(line["progressDetail"]["current"])
85+
total = float(line["progressDetail"]["total"])
8186
except KeyError:
82-
return ""
83-
progress = current / total
84-
if progress > 1.0:
85-
progress == 1.0
86-
return "Complete: {:.1%}\n".format(progress)
87-
88-
return ""
87+
return 0
88+
result = (current / total) * 100
89+
if result > 100.0:
90+
return 100.0
91+
return result
92+
return 0
8993

9094

9195
def build_and_push_image(repo_url: str, tag: str, path: str, image_type: str) -> None:

0 commit comments

Comments
 (0)