2024-05-15 23:39:20 +03:00
|
|
|
import pandas
|
|
|
|
import humanize
|
2024-05-10 17:03:05 +03:00
|
|
|
from nicegui import ui
|
2024-05-15 23:39:20 +03:00
|
|
|
from utils.registry import DockerRegistry
|
|
|
|
|
|
|
|
|
|
|
|
## TODO: this should be async but I currently don't know how to implement this without button press
|
|
|
|
def get_image_info() -> pandas.DataFrame:
|
2024-05-27 09:55:44 +03:00
|
|
|
data = pandas.DataFrame(columns=["image", "tag", "size"])
|
2024-05-20 21:13:34 +03:00
|
|
|
try:
|
|
|
|
registry = DockerRegistry()
|
|
|
|
all_image_info = registry.get_all_image_info()
|
|
|
|
except Exception as error:
|
|
|
|
ui.notify(message=error)
|
|
|
|
return data
|
2024-05-15 23:39:20 +03:00
|
|
|
if isinstance(all_image_info, list) and len(all_image_info) > 0:
|
|
|
|
data = pandas.json_normalize(
|
|
|
|
all_image_info,
|
|
|
|
record_path=["tags"],
|
|
|
|
meta=[["name"]],
|
|
|
|
meta_prefix="image_",
|
|
|
|
).assign(
|
|
|
|
size=lambda x: x["manifest.layers"].apply(
|
|
|
|
lambda layers: sum(layer["size"] for layer in layers)
|
|
|
|
)
|
|
|
|
)
|
2024-05-26 21:52:26 +03:00
|
|
|
data = (
|
|
|
|
data[["image_name", "name", "size"]]
|
|
|
|
.rename(columns={"image_name": "image", "name": "tag", "size": "size"})
|
|
|
|
.sort_values(by=["image", "tag"], ascending=False)
|
2024-05-15 23:39:20 +03:00
|
|
|
)
|
|
|
|
data["size"] = data["size"].apply(humanize.naturalsize)
|
|
|
|
return data
|
|
|
|
else:
|
|
|
|
ui.notify(message="No images found")
|
|
|
|
return data
|
2024-05-10 17:03:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
def content() -> None:
|
2024-05-15 23:39:20 +03:00
|
|
|
with ui.row().classes("w-full"):
|
|
|
|
with ui.card().classes("w-full"):
|
|
|
|
ui.label("Image Overview").classes("text-h5")
|
|
|
|
data = get_image_info()
|
2024-05-26 21:52:26 +03:00
|
|
|
with ui.table.from_pandas(df=data).classes("w-full") as table:
|
|
|
|
table.columns[0]["sortable"] = True
|
|
|
|
table.columns[1]["sortable"] = True
|
|
|
|
table.columns[2]["sortable"] = True
|