mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 02:05:22 -04:00
Clarify Docker dependency status inside containers
* fix: show docker as N/A inside the container * test: cover in-container docker detection * fix: make the N/A dependency chip legible * refactor: make remote docker applicability explicit and tested
This commit is contained in:
+51
-11
@@ -9,6 +9,7 @@ import shutil
|
||||
import subprocess
|
||||
import uuid
|
||||
import tempfile
|
||||
from collections import namedtuple
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any
|
||||
|
||||
@@ -61,6 +62,36 @@ logger = logging.getLogger(__name__)
|
||||
PTY_SUPPORTED = pty is not None and fcntl is not None and hasattr(os, "setsid")
|
||||
|
||||
|
||||
DOCKER_IN_CONTAINER_HINT = (
|
||||
"Not available inside the Odysseus container by design. The image ships no "
|
||||
"docker CLI and no host socket is mounted. Run Docker-backed launches on a "
|
||||
"remote server, where docker is checked over SSH. Mounting /var/run/docker.sock "
|
||||
"into the container would grant it host-root access, so only do that if you "
|
||||
"accept that risk."
|
||||
)
|
||||
|
||||
|
||||
def _running_in_container(dockerenv_path="/.dockerenv", cgroup_path="/proc/1/cgroup"):
|
||||
if os.path.exists(dockerenv_path):
|
||||
return True
|
||||
try:
|
||||
with open(cgroup_path, "r", encoding="utf-8") as fh:
|
||||
contents = fh.read()
|
||||
except OSError:
|
||||
return False
|
||||
return any(token in contents for token in ("docker", "containerd", "kubepods"))
|
||||
|
||||
|
||||
DockerRowStatus = namedtuple("DockerRowStatus", ["applicable", "install_hint"])
|
||||
|
||||
|
||||
def _docker_row_status(*, on_remote, in_container, installed, default_hint):
|
||||
local_docker_unavailable = not on_remote and in_container and not installed
|
||||
if local_docker_unavailable:
|
||||
return DockerRowStatus(applicable=False, install_hint=DOCKER_IN_CONTAINER_HINT)
|
||||
return DockerRowStatus(applicable=True, install_hint=default_hint)
|
||||
|
||||
|
||||
def _find_line_break(buf):
|
||||
"""Find next line terminator in buffer. Returns (index, separator_length) or (-1, 0)."""
|
||||
ni = buf.find(b"\n")
|
||||
@@ -702,20 +733,29 @@ def setup_shell_routes() -> APIRouter:
|
||||
pass
|
||||
|
||||
for pkg in packages:
|
||||
if host and pkg.get("target") == "remote":
|
||||
on_remote = bool(host and pkg.get("target") == "remote")
|
||||
if on_remote:
|
||||
pkg["installed"] = bool(remote_status.get(pkg["name"], False))
|
||||
continue
|
||||
if pkg.get("kind") == "system":
|
||||
elif pkg.get("kind") == "system":
|
||||
pkg["installed"] = shutil.which(pkg["name"]) is not None
|
||||
continue
|
||||
try:
|
||||
if pkg["name"] == "llama_cpp" and shutil.which("llama-server"):
|
||||
pkg["installed"] = True
|
||||
continue
|
||||
importlib.import_module(pkg["name"])
|
||||
elif pkg["name"] == "llama_cpp" and shutil.which("llama-server"):
|
||||
pkg["installed"] = True
|
||||
except ImportError:
|
||||
pkg["installed"] = False
|
||||
else:
|
||||
try:
|
||||
importlib.import_module(pkg["name"])
|
||||
pkg["installed"] = True
|
||||
except ImportError:
|
||||
pkg["installed"] = False
|
||||
|
||||
if pkg["name"] == "docker":
|
||||
status = _docker_row_status(
|
||||
on_remote=on_remote,
|
||||
in_container=_running_in_container() if not on_remote else False,
|
||||
installed=pkg["installed"],
|
||||
default_hint=pkg.get("install_hint"),
|
||||
)
|
||||
pkg["applicable"] = status.applicable
|
||||
pkg["install_hint"] = status.install_hint
|
||||
return {"packages": packages}
|
||||
|
||||
@router.post("/api/cookbook/packages/install")
|
||||
|
||||
Reference in New Issue
Block a user