feat(hub): add auto-update switches for on/off & acquisition modes and remove manual download buttons from webui
CI Test Suite / Run Component Tests & Pipeline Verification (push) Successful in 2m21s
CI Test Suite / Run Component Tests & Pipeline Verification (push) Successful in 2m21s
This commit is contained in:
@@ -26,12 +26,16 @@ class ServerUpdateManager:
|
||||
self,
|
||||
update_dir: Optional[str] = None,
|
||||
upstream_url: Optional[str] = None,
|
||||
check_enabled: bool = True
|
||||
check_enabled: bool = True,
|
||||
auto_update_enabled: bool = True,
|
||||
update_mode: str = "auto"
|
||||
):
|
||||
self.update_dir = update_dir or os.path.join(os.getcwd(), "updates")
|
||||
os.makedirs(self.update_dir, exist_ok=True)
|
||||
self.upstream_url = upstream_url or self.DEFAULT_GITEA_RELEASE_URL
|
||||
self.check_enabled = check_enabled
|
||||
self.auto_update_enabled = auto_update_enabled
|
||||
self.update_mode = update_mode.lower() if update_mode else "auto"
|
||||
|
||||
# Cached upstream release state
|
||||
self.last_checked_utc: Optional[str] = None
|
||||
@@ -275,7 +279,17 @@ class ServerUpdateManager:
|
||||
has_pkg = bool(pkg.get("exists"))
|
||||
client_ver = (current_version or "0.0.0.0").strip().lstrip("v")
|
||||
|
||||
# An update is available if the hosted version is strictly newer than the client version
|
||||
# An update is available if auto_update is enabled, package exists, and hosted version is strictly newer
|
||||
if not self.auto_update_enabled:
|
||||
return {
|
||||
"update_available": False,
|
||||
"client_id": client_id,
|
||||
"os": norm_os,
|
||||
"current_version": client_ver,
|
||||
"latest_version": target_version,
|
||||
"reason": "Fleet auto-update is disabled on this server."
|
||||
}
|
||||
|
||||
update_available = has_pkg and is_newer_version(target_version, client_ver)
|
||||
|
||||
return {
|
||||
@@ -377,10 +391,21 @@ class ServerUpdateManager:
|
||||
|
||||
return results
|
||||
|
||||
def sync_upstream_packages(self, force: bool = True, timeout: int = 60) -> Dict[str, Any]:
|
||||
"""
|
||||
Manually or programmatically triggers an immediate upstream release check and downloads
|
||||
the latest client binary packages to the Hub repository.
|
||||
"""
|
||||
self.check_upstream_updates(force=force, auto_download_clients=True, timeout=timeout)
|
||||
if self.release_assets:
|
||||
return self.download_and_cache_client_packages(assets=self.release_assets, timeout=timeout)
|
||||
return {"windows": False, "linux": False, "downloaded": [], "error": self.last_error or "No release assets found."}
|
||||
|
||||
def check_upstream_updates(self, force: bool = False, auto_download_clients: bool = True, timeout: int = 15) -> Dict[str, Any]:
|
||||
"""
|
||||
Queries the upstream repository release API (Gitea / GitHub / JSON manifest)
|
||||
to check if a newer server or client release is available, and automatically caches client packages.
|
||||
to check if a newer server or client release is available, and automatically caches client packages
|
||||
when in automatic acquisition mode.
|
||||
"""
|
||||
if not self.check_enabled and not force:
|
||||
return self.get_status()
|
||||
@@ -423,9 +448,9 @@ class ServerUpdateManager:
|
||||
if self.server_update_available:
|
||||
print(f"[!] 🔔 LOGAR Server Update Available: Current v{LOGAR_VERSION} -> Upstream v{upstream_ver}")
|
||||
|
||||
# Automatically download and cache client update packages on the Hub
|
||||
if auto_download_clients and assets:
|
||||
# Check if hosted packages need updating
|
||||
# Automatically download and cache client update packages on the Hub if in auto mode
|
||||
should_auto_download = auto_download_clients and (self.update_mode == "auto" or force)
|
||||
if should_auto_download and assets:
|
||||
hosted = self.get_hosted_packages()
|
||||
needs_win = not hosted.get("windows", {}).get("exists") or is_newer_version(upstream_ver, hosted.get("windows", {}).get("version", "0.0.0"))
|
||||
needs_linux = not hosted.get("linux", {}).get("exists") or is_newer_version(upstream_ver, hosted.get("linux", {}).get("version", "0.0.0"))
|
||||
@@ -452,5 +477,8 @@ class ServerUpdateManager:
|
||||
"last_checked_utc": self.last_checked_utc,
|
||||
"last_error": self.last_error,
|
||||
"check_enabled": self.check_enabled,
|
||||
"auto_update_enabled": self.auto_update_enabled,
|
||||
"update_mode": self.update_mode,
|
||||
"upstream_url": self.upstream_url,
|
||||
"hosted_packages": self.get_hosted_packages()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user