]> git.giorgioravera.it Git - network-manager.git/commitdiff
updated health to include baseimg versions
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Tue, 6 Jan 2026 20:45:34 +0000 (21:45 +0100)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Tue, 6 Jan 2026 20:45:34 +0000 (21:45 +0100)
backend/config.py
backend/routes/health.py
entrypoint.py

index f7ee9988e17879910212250174b55d14d69f9020..6ebb929e7bec8afc63aa3a09e15c06cef01ea044 100644 (file)
@@ -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"
 
index 2a68d125f872f5ccb3a9500d50e194e8c0d2b2f2..528c206d7fc9d26cc7256a61cbd08adf42600ddd 100644 (file)
@@ -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
+        }
+    }
+
index 1e2fd80a8b936ce20365779c7096f414cf48cf28..5213628459f891cb1adbf85afd260686bb544527 100755 (executable)
@@ -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:]