From: Giorgio Ravera Date: Tue, 6 Jan 2026 20:45:34 +0000 (+0100) Subject: updated health to include baseimg versions X-Git-Tag: v0.0.1~39 X-Git-Url: http://git.giorgioravera.it/?a=commitdiff_plain;h=711cb76d7fe33e0e543012b5ab46d9885e8a23e1;p=network-manager.git updated health to include baseimg versions --- diff --git a/backend/config.py b/backend/config.py index f7ee998..6ebb929 100644 --- a/backend/config.py +++ b/backend/config.py @@ -1,11 +1,25 @@ # backend/config.py # Import standard modules +import datetime import os import secrets # Import local modules from backend.utils import load_hash +# Software Version +BASE_VERSION = "0.1.0" +DEVEL = os.getenv("DEV", "0") == "1" +if DEVEL: + timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M") + APP_VERSION = f"{BASE_VERSION}-dev-{timestamp}" +else: + APP_VERSION = BASE_VERSION + +# Base Image / Docker Image +BASEIMG_NAME = os.getenv("BASEIMG_NAME", "unknown") +BASEIMG_VERSION = os.getenv("BASEIMG_VERSION", "unknown") + # Frontend related settings FRONTEND_DIR = "/app/frontend" diff --git a/backend/routes/health.py b/backend/routes/health.py index 2a68d12..528c206 100644 --- a/backend/routes/health.py +++ b/backend/routes/health.py @@ -1,6 +1,12 @@ # backend/health.py +# Import standard modules from fastapi import APIRouter +import sqlite3 +import time +import os +# Import config variables +from backend.config import APP_VERSION, BASEIMG_NAME, BASEIMG_VERSION, DB_FILE # Create Router router = APIRouter() @@ -9,6 +15,50 @@ router = APIRouter() # API ENDPOINTS # --------------------------------------------------------- -@router.get("/health", tags=["health"]) -def health_check(): - return {"status": "ok"} +@router.get("/api/health", tags=["health"]) +def health(): + start = time.time() + + db_status = "ok" + db_version = None + db_tables = None + db_size = None + + try: + conn = sqlite3.connect(DB_FILE) + cursor = conn.cursor() + + cursor.execute("select sqlite_version()") + db_version = cursor.fetchone()[0] + + cursor.execute("select count(*) from sqlite_master where type='table'") + db_tables = cursor.fetchone()[0] + + conn.close() + + db_size = round(os.path.getsize(DB_FILE) / (1024 * 1024), 2) + + except Exception as e: + db_status = "error" + db_version = str(e) + + latency = round((time.time() - start) * 1000, 2) + + return { + "status": "ok" if db_status == "ok" else "degraded", + "app": { + "version": APP_VERSION + }, + "baseimg": { + "name": BASEIMG_NAME, + "version": BASEIMG_VERSION + }, + "latency_ms": latency, + "database": { + "status": db_status, + "version": db_version, + "tables": db_tables, + "size_mb": db_size + } + } + diff --git a/entrypoint.py b/entrypoint.py index 1e2fd80..5213628 100755 --- a/entrypoint.py +++ b/entrypoint.py @@ -11,8 +11,8 @@ import backend.db.users # ================================ # Variables # ================================ -IMAGE_NAME = "network-manager-distroless" -IMAGE_VERSION = "1.0" +BASEIMG_NAME = "network-manager-distroless" +BASEIMG_VERSION = "0.2" from backend.config import DB_FILE from backend.config import DB_RESET @@ -46,7 +46,9 @@ def docker_create_db(): # Force flush sys.stdout.reconfigure(line_buffering=True) -print(f"INFO: Starting {IMAGE_NAME} docker image version {IMAGE_VERSION}.") +print(f"INFO: Starting {BASEIMG_NAME} docker image version {BASEIMG_VERSION}.") +os.environ["BASEIMG_NAME"] = BASEIMG_NAME +os.environ["BASEIMG_VERSION"] = BASEIMG_VERSION # Parse arguments args = sys.argv[1:]