Files
ProxMenux/oci/src/proxmenux_oci/images.py
T
MacRimiandClaude Opus 5 bcabcb618c feat(oci): run official container images as native LXC containers
Adds the OCI manager: an engine that turns a Docker Compose file into an
LXC definition, a catalog of 365 applications drawn from LinuxServer.io
and other container image sources, and a per-instance registry recording
what each container was built from. Reachable from the main menu.

Catalog text is translated like every other string in the project: the
taglines go through translate() and land in lang/*.json, so the entries
read in all eight languages instead of only English.

Translation cache builder:
- a failed translation leaves the key absent rather than writing English,
  which previously made the string count as translated forever
- a result identical to a 3+ word source is rejected, catching a provider
  that silently returns the text it was given
- strings that are nothing but glossary terms keep their source spelling
  instead of being discarded as failures
- no backoff between attempts when the provider is deterministic
- application names are protected so "HAOS One" survives translation
- argos joins the provider list, and the workflow reads the OCI sources

Audit & Report:
- findings that moved in the wrong direction between runs are reported
  alongside the ones that improved
- an accepted risk can carry a review date and is flagged when it falls due
- backup checks explain in plain language what they looked at and what to
  do next

Monitor:
- disks can be excluded from periodic reads, and an idle disk says so
  instead of showing a stale temperature
- per-disk identity survives a controller or enclosure change
- scheduled Borg backups resolve their SSH key from the repository entry
- PVE upgrades log the package list and the resulting dpkg changes

The web build no longer copies scripts/ into public/: the documentation
links to GitHub, so nothing read that folder.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-22 18:24:59 +02:00

52 lines
2.2 KiB
Python

"""The downloaded OCI images an installation was created from: the container
does not need them once it exists, so the user may delete them."""
from __future__ import annotations
import json
import subprocess
import sys
from pathlib import Path
from typing import Any
from . import console
from .i18n import translate
PROJECT_ROOT = Path(__file__).resolve().parents[2]
def _cache(command: str, vmids: list[int]) -> dict[str, Any] | None:
result = subprocess.run([sys.executable, str(PROJECT_ROOT / "remote" / "oci_image_cache.py"), command,
*map(str, vmids)], capture_output=True, text=True, check=False)
try:
return json.loads(result.stdout) if result.returncode == 0 else None
except ValueError:
return None
def size_text(size: int) -> str:
return f"{size / 1024**3:.1f} GB" if size >= 1024**3 else f"{max(1, round(size / 1024**2))} MB"
def offer_removal(ui, vmids: list[int]) -> tuple[bool, str | None]:
"""Asks whether to delete the images of these installations. Returns whether
the question was shown and the line to report when they were deleted."""
listed = _cache("list", vmids)
archives = (listed or {}).get("archives") or []
if not archives:
return False, None
total = size_text(sum(item["size"] for item in archives))
if len(archives) == 1:
text = (f"{translate('The container was created from a downloaded OCI image')} ({total}). "
f"{translate('The container does not need it any more; an update downloads the new version when there is one.')}"
f"\n\n{translate('Delete the image to free the space?')}")
else:
text = (f"{translate('The containers were created from downloaded OCI images')} ({len(archives)}, {total}). "
f"{translate('The containers do not need them any more; an update downloads the new versions when there are any.')}"
f"\n\n{translate('Delete the images to free the space?')}")
if not console.ask_yes_no(text, True):
return True, None
removed = _cache("remove", vmids)
if not removed or not removed.get("freed"):
return True, None
return True, f"{translate('Downloaded OCI images deleted:')} {size_text(removed['freed'])}"