From 8f64760add790978d00c0b0575d6cf121fedc678 Mon Sep 17 00:00:00 2001 From: Martin Tazl Date: Tue, 7 Jul 2026 16:12:12 +0200 Subject: [PATCH] show build on website footer --- PROJECT_KNOWLEDGE.md | 21 +++++++++++++++++++ README.md | 15 ++++++++++++++ access_log.json | 7 +++++++ app.py | 37 ++++++++++++++++++++++++++++++++++ build_info.json | 6 ++++++ scripts/update_build_info.sh | 16 +++++++++++++++ templates/roll_calculator.html | 4 ++++ 7 files changed, 106 insertions(+) create mode 100644 build_info.json create mode 100755 scripts/update_build_info.sh diff --git a/PROJECT_KNOWLEDGE.md b/PROJECT_KNOWLEDGE.md index b638b7d..517bf4a 100644 --- a/PROJECT_KNOWLEDGE.md +++ b/PROJECT_KNOWLEDGE.md @@ -20,6 +20,7 @@ Backend: - `/api/health` returns health/version information. - `/api/user` returns the authenticated user. - Access events are appended to `access_log.json`. +- `build_info.json` is loaded at startup and exposed to all templates as `build_info`. Frontend: @@ -28,6 +29,26 @@ Frontend: - `window.ARTICLE_DATA` is loaded from `/static/article-data.json`. - `window.APP_CONFIG` is currently defined inline for forklift rules. - A disclaimer modal blocks use until the user checks the confirmation checkbox. +- The footer displays build metadata: version, branch, commit, and timestamp. + +## Build Info + +Build/deployment metadata is read from: + +```text +build_info.json +``` + +Expected fields: + +- `version` +- `branch` +- `commit` +- `timestamp` + +If `build_info.json` is missing, malformed, or does not contain a usable value, RollCalc falls back to `unknown` for that value and continues serving the site. + +The data is loaded centrally in `app.py` and made available to every template as `build_info`. ## Roll Geometry diff --git a/README.md b/README.md index d25461a..914894c 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ The app uses HTTP Basic Auth. Current credentials are defined in `BETA_USERS` in ├── app.py ├── requirements.txt ├── README.md +├── build_info.json ├── access_log.json ├── config.json ├── article-data_.json @@ -101,6 +102,7 @@ The template contains: - Page layout and all main CSS. - A disclaimer modal shown after Basic Auth login and before calculator use. +- Footer build metadata from `build_info`. - Global state: - `window.ARTICLE_DATA` - `window.APP_CONFIG` @@ -261,6 +263,19 @@ JSON audit log written by `app.py`. Important implementation detail: each logged access reads and rewrites the entire JSON file. This is simple but not concurrency-safe and can become inefficient as the file grows. +### `build_info.json` + +Deployment/build metadata displayed in the site footer. + +Expected fields: + +- `version` +- `branch` +- `commit` +- `timestamp` + +`app.py` loads this file centrally at startup and exposes it to all templates as `build_info`. If the file is missing, invalid, or a field is empty, the affected values fall back to `unknown` and the website continues to work. + ### `fix_article_data.py` Utility script that updates relative frontend fetch/register paths to Flask-style `/static/...` paths and checks that key static files exist. diff --git a/access_log.json b/access_log.json index 596ded2..6f51800 100644 --- a/access_log.json +++ b/access_log.json @@ -621,5 +621,12 @@ "endpoint": "/", "method": "GET", "status": 200 + }, + { + "timestamp": "2026-07-07T14:46:22.335316", + "username": "mtazl", + "endpoint": "/", + "method": "GET", + "status": 200 } ] \ No newline at end of file diff --git a/app.py b/app.py index d93eb7d..76f3c24 100644 --- a/app.py +++ b/app.py @@ -29,6 +29,43 @@ BETA_USERS = { # Logging für Auditing LOG_FILE = "access_log.json" +BUILD_INFO_FILE = "build_info.json" +UNKNOWN_BUILD_INFO = { + "version": "unknown", + "branch": "unknown", + "commit": "unknown", + "timestamp": "unknown" +} + +# ============================================================================ +# BUILD INFO +# ============================================================================ + +def load_build_info(): + """Load deployment/build metadata for templates.""" + try: + with open(BUILD_INFO_FILE, "r") as f: + data = json.load(f) + except Exception as e: + print(f"[Build Info Error] {e}") + return UNKNOWN_BUILD_INFO.copy() + + if not isinstance(data, dict): + return UNKNOWN_BUILD_INFO.copy() + + build_info = UNKNOWN_BUILD_INFO.copy() + for key in build_info: + value = data.get(key) + if isinstance(value, str) and value.strip(): + build_info[key] = value.strip() + return build_info + +BUILD_INFO = load_build_info() + +@app.context_processor +def inject_build_info(): + """Make build metadata available in all templates.""" + return {"build_info": BUILD_INFO} # ============================================================================ # AUTHENTICATION diff --git a/build_info.json b/build_info.json new file mode 100644 index 0000000..213cbe8 --- /dev/null +++ b/build_info.json @@ -0,0 +1,6 @@ +{ + "version": "0.4", + "branch": "develop/v0.4", + "commit": "ffa3481", + "timestamp": "2026-07-07T10:26:13Z" +} diff --git a/scripts/update_build_info.sh b/scripts/update_build_info.sh new file mode 100755 index 0000000..4cb9780 --- /dev/null +++ b/scripts/update_build_info.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" + +cd "$PROJECT_ROOT" + +cat > build_info.json < Naue GmbH & Co. KG · Roll Diameter Calculator · Internal Application +