ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(system): version resolution honors custom install dirs and Docker
Juan Denise797ec3a3fab
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0dacc03d..1547fd55 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -281,6 +281,12 @@ awaiting a stable release:- Hardened the installer: Docker install on Fedora/RHEL, SELinux + nginxreverse-proxy configuration, and low-RAM swap setup.- Stopped dropping capability/sysinfo payloads on transient `/poll` failures.+- Settings → About now reports the real panel version on custom-directory+ installs and in Docker: version resolution honors the install location+ (`SERVERKIT_INSTALL_DIR`, rendered into the service unit from the installer's+ `SERVERKIT_DIR`), prefers the running tree over a stale `/opt/serverkit`, and+ the Docker image now ships the `VERSION` file (containers previously showed+ the `1.0.0` fallback).- **Scripts reliability (round 2)** — swept the whole install/update/uninstall/CLIshell surface for the "benign non-zero under `set -e`/`pipefail`" failure classbehind the July 2 update outage:diff --git a/Dockerfile b/Dockerfileindex f9204160..9e9deb8a 100644--- a/Dockerfile+++ b/Dockerfile@@ -76,6 +76,10 @@ RUN pip install --no-cache-dir -r backend/requirements.txt# Copy backend sourceCOPY backend/ ./backend/+# Ship the VERSION file next to the backend tree (/app/VERSION) so the panel+# reports its real version in containers instead of the unknown-version fallback+COPY VERSION ./VERSION+# Copy built frontend from Stage 1COPY --from=frontend-builder /app/frontend/dist ./frontend/distdiff --git a/backend/app/api/system.py b/backend/app/api/system.pyindex 6cdcd40e..8fd65345 100644--- a/backend/app/api/system.py+++ b/backend/app/api/system.py@@ -9,6 +9,7 @@ from app.services.system_service import SystemServicefrom app.services.resource_tier_service import ResourceTierServicefrom app.services.site_domain_service import SiteDomainServicefrom app.utils.domain import is_valid_canonical_domain+from app.utils.version import get_panel_version# Cache for update check (to avoid hitting GitHub API too often)_update_cache = {@@ -23,27 +24,13 @@ system_bp = Blueprint('system', __name__)@system_bp.route('/version', methods=['GET'])@jwt_required()def get_version():- """Get ServerKit version."""- version = '1.0.0' # Default version-- # Try to read from VERSION file- version_paths = [- '/opt/serverkit/VERSION',- os.path.join(current_app.root_path, '..', 'VERSION'),- os.path.join(current_app.root_path, '..', '..', 'VERSION'),- ]-- for path in version_paths:- try:- if os.path.exists(path):- with open(path, 'r') as f:- version = f.read().strip()- break- except Exception:- pass+ """Get ServerKit version.+ Resolution (SERVERKIT_INSTALL_DIR override → own tree → /opt/serverkit)+ lives in app.utils.version so custom install dirs report honestly.+ """return jsonify({- 'version': version,+ 'version': get_panel_version(),'name': 'ServerKit'}), 200@@ -58,21 +45,8 @@ def check_update():if _update_cache['result'] and (time.time() - _update_cache['last_check']) < _update_cache['ttl']:return jsonify(_update_cache['result']), 200- # Get current version- current_version = '1.0.0'- version_paths = [- '/opt/serverkit/VERSION',- os.path.join(current_app.root_path, '..', 'VERSION'),- os.path.join(current_app.root_path, '..', '..', 'VERSION'),- ]- for path in version_paths:- try:- if os.path.exists(path):- with open(path, 'r') as f:- current_version = f.read().strip()- break- except Exception:- pass+ # Get current version (shared resolver — honors SERVERKIT_INSTALL_DIR)+ current_version = get_panel_version()result = {'current_version': current_version,diff --git a/backend/app/utils/crypto.py b/backend/app/utils/crypto.pyindex 98d2afa1..c3846a1f 100644--- a/backend/app/utils/crypto.py+++ b/backend/app/utils/crypto.py@@ -27,6 +27,14 @@ def _find_env_file() -> Path:candidates = []+ # SERVERKIT_INSTALL_DIR is rendered into the systemd unit from the+ # installer's SERVERKIT_DIR — the unambiguous "where is the install" var+ # (the bare SERVERKIT_DIR name doubles as the /var/serverkit data root in+ # app/paths.py, so it stays a lower-priority hint here).+ install_dir = os.environ.get('SERVERKIT_INSTALL_DIR')+ if install_dir:+ candidates.append(Path(install_dir) / '.env')+# SERVERKIT_DIR is used by the CLI and install scriptserverkit_dir = os.environ.get('SERVERKIT_DIR')if serverkit_dir:diff --git a/backend/app/utils/version.py b/backend/app/utils/version.pyindex d23af1ef..9ff904fb 100644--- a/backend/app/utils/version.py+++ b/backend/app/utils/version.py@@ -23,11 +23,22 @@ def get_panel_version():here = os.path.dirname(os.path.abspath(__file__)) # backend/app/utilsbackend_root = os.path.dirname(os.path.dirname(here)) # backend/- candidates = [- '/opt/serverkit/VERSION',- os.path.join(backend_root, '..', 'VERSION'),- os.path.join(backend_root, 'VERSION'),- ]+ candidates = []+ # Explicit override first — the systemd unit renders SERVERKIT_INSTALL_DIR+ # from the installer's SERVERKIT_DIR, so custom install locations are+ # pinned positively. Deliberately NOT the bare SERVERKIT_DIR env var: the+ # backend already uses that name for the /var/serverkit data root+ # (app/paths.py), a different directory with a different default.+ install_dir = os.environ.get('SERVERKIT_INSTALL_DIR')+ if install_dir:+ candidates.append(os.path.join(install_dir, 'VERSION'))+ # The running code's own tree next: correct for any custom install dir and+ # for the Docker image (/app/VERSION), and never a stale parallel tree.+ candidates.append(os.path.join(backend_root, '..', 'VERSION'))+ candidates.append(os.path.join(backend_root, 'VERSION'))+ # Legacy default install location last — a box moved to a custom dir may+ # still have an abandoned tree here.+ candidates.append('/opt/serverkit/VERSION')version = '0.0.0'for path in candidates:try:diff --git a/backend/tests/test_panel_version.py b/backend/tests/test_panel_version.pynew file mode 100644index 00000000..582aeb99--- /dev/null+++ b/backend/tests/test_panel_version.py@@ -0,0 +1,71 @@+"""Panel version resolution — the About page's version must track the real+install, including a custom SERVERKIT_DIR (rendered into the systemd unit as+SERVERKIT_INSTALL_DIR) and the Docker image layout, never a stale parallel+tree under the default /opt/serverkit.+"""+import os++import pytest++import app.utils.version as version_mod++[email protected](autouse=True)+def _reset_version_cache():+ """get_panel_version caches after first read — isolate every test."""+ version_mod._cached_version = None+ yield+ version_mod._cached_version = None+++def _write_version(dirpath, value):+ path = dirpath / 'VERSION'+ path.write_text(value + '\n', encoding='utf-8')+ return path+++def test_install_dir_override_wins(tmp_path, monkeypatch):+ """SERVERKIT_INSTALL_DIR (a custom install location) is honored first."""+ _write_version(tmp_path, '9.9.9-custom')+ monkeypatch.setenv('SERVERKIT_INSTALL_DIR', str(tmp_path))+ assert version_mod.get_panel_version() == '9.9.9-custom'+++def test_override_without_version_file_falls_through(tmp_path, monkeypatch):+ """A pinned install dir with no VERSION file degrades to the own-tree read+ instead of reporting unknown."""+ monkeypatch.setenv('SERVERKIT_INSTALL_DIR', str(tmp_path)) # empty dir+ repo_root_version = os.path.join(+ os.path.dirname(os.path.abspath(version_mod.__file__)),+ '..', '..', '..', 'VERSION'+ )+ expected = open(repo_root_version, encoding='utf-8').read().strip()+ assert version_mod.get_panel_version() == expected+++def test_own_tree_read_without_override(monkeypatch):+ """No env override: the running code's own tree (repo-root VERSION here,+ /app/VERSION in the Docker image) is the source — not /opt/serverkit."""+ monkeypatch.delenv('SERVERKIT_INSTALL_DIR', raising=False)+ repo_root_version = os.path.join(+ os.path.dirname(os.path.abspath(version_mod.__file__)),+ '..', '..', '..', 'VERSION'+ )+ expected = open(repo_root_version, encoding='utf-8').read().strip()+ got = version_mod.get_panel_version()+ assert got == expected+ assert got != '0.0.0'+++def test_version_endpoint_reports_resolved_version(client, auth_headers, tmp_path, monkeypatch):+ """GET /api/v1/system/version (the About page's source) serves the+ resolver's answer, so a custom SERVERKIT_DIR box reports its real version."""+ _write_version(tmp_path, '8.8.8-endpoint')+ monkeypatch.setenv('SERVERKIT_INSTALL_DIR', str(tmp_path))+ version_mod._cached_version = None++ resp = client.get('/api/v1/system/version', headers=auth_headers)+ assert resp.status_code == 200+ data = resp.get_json()+ assert data['version'] == '8.8.8-endpoint'+ assert data['name'] == 'ServerKit'diff --git a/templates/serverkit-backend.service.in b/templates/serverkit-backend.service.inindex 6c22a6ae..2df26c14 100644--- a/templates/serverkit-backend.service.in+++ b/templates/serverkit-backend.service.in@@ -10,6 +10,7 @@ Group=@USER@WorkingDirectory=@SERVERKIT_DIR@/backendEnvironment="PATH=@SERVERKIT_VENV_DIR@/bin:/usr/local/bin:/usr/bin:/bin"Environment="FLASK_ENV=production"+Environment="SERVERKIT_INSTALL_DIR=@SERVERKIT_DIR@"EnvironmentFile=@SERVERKIT_DIR@/.envExecStart=@SERVERKIT_VENV_DIR@/bin/gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 -b 0.0.0.0:@PORT@ --timeout 120 --access-logfile @LOG_DIR@/access.log --error-logfile @LOG_DIR@/error.log run:appExecReload=/bin/kill -HUP $MAINPID