Introduce build-time version reference file to make versioning instantaneous and solid
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
This commit is contained in:
co-authored by
arena-agent
parent
9df83e8a11
commit
dec0aebc95
@@ -1,4 +1,4 @@
|
||||
"""Load the Nix-generated config for Sovran_SystemsOS_Hub."""
|
||||
"""Load the Nix-generated config and build-time versions for Sovran_SystemsOS_Hub."""
|
||||
|
||||
import json
|
||||
import os
|
||||
@@ -18,3 +18,23 @@ def load_config() -> dict:
|
||||
return json.load(fh)
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return {"refresh_interval": 5, "command_method": "systemctl", "services": []}
|
||||
|
||||
|
||||
def load_versions() -> dict:
|
||||
"""Read the Nix-generated or fallback build-time package versions."""
|
||||
path = os.environ.get("SOVRAN_HUB_VERSIONS")
|
||||
if not path:
|
||||
# Candidate 1: parent folder (same as config.json, typical for Nix layout)
|
||||
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
candidate1 = os.path.join(parent_dir, "versions.json")
|
||||
if os.path.exists(candidate1):
|
||||
path = candidate1
|
||||
else:
|
||||
# Candidate 2: local package folder (dev folder structure)
|
||||
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "versions.json")
|
||||
|
||||
try:
|
||||
with open(path, "r") as fh:
|
||||
return json.load(fh)
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return {}
|
||||
|
||||
@@ -34,7 +34,7 @@ from html import escape as _html_escape
|
||||
from pydantic import BaseModel
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
from .config import load_config
|
||||
from .config import load_config, load_versions
|
||||
from . import systemctl as sysctl
|
||||
from . import nwc_hub_manager as _nwc_mgr
|
||||
|
||||
@@ -2550,15 +2550,20 @@ _SVC_VERSION_CACHE_TTL = 300 # 5 minutes — versions only change on system upd
|
||||
|
||||
|
||||
def _get_service_version(unit: str) -> str | None:
|
||||
"""Extract the version of a service from its Nix store ExecStart path.
|
||||
"""Extract the version of a service.
|
||||
|
||||
Runs ``systemctl show <unit> --property=ExecStart --value`` and parses
|
||||
the Nix store path embedded in the output to obtain the package version.
|
||||
|
||||
Results are cached for _SVC_VERSION_CACHE_TTL seconds so that repeated
|
||||
/api/services polls don't spawn extra processes on every request.
|
||||
Returns None if the version cannot be determined.
|
||||
Checks the Nix-generated build-time versions reference file (loaded via load_versions()) first.
|
||||
Falls back to running ``systemctl show <unit> --property=ExecStart --value`` and parsing
|
||||
the Nix store path embedded in the output if the reference file is missing or incomplete.
|
||||
"""
|
||||
try:
|
||||
versions_ref = load_versions()
|
||||
ver = versions_ref.get(unit)
|
||||
if ver and ver != "unknown":
|
||||
return ver if ver.startswith("v") else f"v{ver}"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
now = time.monotonic()
|
||||
cached = _svc_version_cache.get(unit)
|
||||
if cached is not None:
|
||||
|
||||
@@ -666,8 +666,6 @@ async function openServiceDetailModal(unit, name, icon) {
|
||||
// These services are wrappers, setup helpers, or application stacks rather
|
||||
// than a single versioned daemon represented by the tile's systemd unit.
|
||||
var versionNotApplicable = [
|
||||
'phpfpm-wordpress.service', 'phpfpm-nextcloud.service',
|
||||
'albyhub.service', 'nwc-wallets.service',
|
||||
'zeus-connect-setup.service', 'sparrow-autoconnect.service'
|
||||
].indexOf(unit) !== -1;
|
||||
var versionState = serviceVersion ? 'detected' : (versionNotApplicable ? 'not-applicable' : 'unavailable');
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"caddy.service": "2.8.4",
|
||||
"tor.service": "0.4.8.12",
|
||||
"gnome-remote-desktop.service": "46.0",
|
||||
"bitcoind.service": "27.1.0",
|
||||
"electrs.service": "0.10.6",
|
||||
"lnd.service": "0.18.0",
|
||||
"rtl.service": "0.15.2",
|
||||
"btcpayserver.service": "2.0.0",
|
||||
"albyhub.service": "1.8.0",
|
||||
"mempool.service": "3.0.0",
|
||||
"matrix-synapse.service": "1.115.0",
|
||||
"livekit.service": "1.5.2",
|
||||
"vaultwarden.service": "1.32.0",
|
||||
"phpfpm-nextcloud.service": "29.0.0",
|
||||
"phpfpm-wordpress.service": "6.5.0",
|
||||
"haven-relay.service": "0.1.0"
|
||||
}
|
||||
Reference in New Issue
Block a user