# 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"
# 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()
# 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
+ }
+ }
+
# ================================
# 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
# 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:]