Show deployed git commit in the site footer.

Resolve build ref from git locally or GIT_COMMIT at Docker build time, linked to the Gitea commit page.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-05 11:42:41 +02:00
co-authored by Cursor
parent fd364218ec
commit 3864d36573
8 changed files with 77 additions and 4 deletions
+1
View File
@@ -3,6 +3,7 @@ __pycache__/
*.pyc
data/
*.db
BUILD_REF
fantasyidler_save.json
.gitea-credentials.txt
testfiles/
+5 -2
View File
@@ -2,6 +2,8 @@ FROM python:3.12-slim
WORKDIR /app
ARG GIT_COMMIT=unknown
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
DATA_DIR=/data \
@@ -13,12 +15,13 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py db.py parser.py categories.py validation.py viewers.py security.py game_data.py advisor.py ./
COPY app.py db.py parser.py categories.py validation.py viewers.py security.py game_data.py advisor.py version.py ./
COPY game_data/ game_data/
COPY templates/ templates/
COPY static/ static/
RUN mkdir -p /data/viewers /data/uploads \
RUN echo "$GIT_COMMIT" > BUILD_REF \
&& mkdir -p /data/viewers /data/uploads \
&& useradd --create-home --uid 1000 --shell /usr/sbin/nologin appuser \
&& chown -R appuser:appuser /app /data
+11
View File
@@ -46,6 +46,7 @@ from security import (
limiter,
local_viewer_disabled,
)
from version import build_info
from viewers import (
LOCAL_VIEWER_ID,
create_viewer,
@@ -60,6 +61,16 @@ from viewers import (
app = Flask(__name__)
configure_app(app)
@app.context_processor
def inject_build_info():
info = build_info()
return {
"build_ref": info.get("ref"),
"build_url": info.get("url"),
}
DATA_DIR = Path(os.environ.get("DATA_DIR", Path(__file__).parent / "data"))
DB_PATH = DEFAULT_DB
STATIC_DIR = Path(__file__).parent / "static"
+4 -1
View File
@@ -1,6 +1,9 @@
services:
viewer:
build: .
build:
context: .
args:
GIT_COMMIT: ${GIT_COMMIT:-unknown}
ports:
- "5000:5000"
environment:
+1
View File
@@ -41,6 +41,7 @@ if [[ "$ACTUAL_SHA" != "$EXPECTED_SHA" ]]; then
fi
info "Rebuilding and starting containers…"
export GIT_COMMIT="$ACTUAL_SHA"
docker compose up -d --build --remove-orphans
wait_for_docker_health() {
+9
View File
@@ -918,6 +918,15 @@ body.inv-chart-modal-open {
text-decoration: underline;
}
.site-footer .build-ref {
font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, monospace;
color: var(--text-muted);
}
.site-footer .build-ref:hover {
color: var(--accent);
}
.landing-page .site-footer {
width: 100%;
max-width: 520px;
+1 -1
View File
@@ -1,3 +1,3 @@
<footer class="site-footer">
<p>© 2026 <a href="https://dashy.elpatron.me" target="_blank" rel="noopener noreferrer">KnorrLabs</a> <a href="https://gitea.elpatron.me/elpatron/Idle-Fantasy-Save-Viewer" target="_blank" rel="noopener noreferrer">Source Code</a></p>
<p>© 2026 <a href="https://dashy.elpatron.me" target="_blank" rel="noopener noreferrer">KnorrLabs</a> <a href="https://gitea.elpatron.me/elpatron/Idle-Fantasy-Save-Viewer" target="_blank" rel="noopener noreferrer">Source Code</a>{% if build_ref and build_url %} <a href="{{ build_url }}" target="_blank" rel="noopener noreferrer" class="build-ref" title="Deployed commit">{{ build_ref }}</a>{% endif %}</p>
</footer>
+45
View File
@@ -0,0 +1,45 @@
"""Deployed build reference (git commit), without semver."""
from __future__ import annotations
import os
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parent
BUILD_REF_FILE = ROOT / "BUILD_REF"
REPO_URL = "https://gitea.elpatron.me/elpatron/Idle-Fantasy-Save-Viewer"
def _git_head() -> str | None:
try:
return subprocess.check_output(
["git", "rev-parse", "HEAD"],
cwd=ROOT,
stderr=subprocess.DEVNULL,
text=True,
).strip() or None
except (OSError, subprocess.CalledProcessError):
return None
def build_commit() -> str | None:
env_ref = os.environ.get("GIT_COMMIT", "").strip()
if env_ref and env_ref != "unknown":
return env_ref
if BUILD_REF_FILE.is_file():
ref = BUILD_REF_FILE.read_text(encoding="utf-8").strip()
if ref and ref != "unknown":
return ref
return _git_head()
def build_info() -> dict[str, str | None]:
commit = build_commit()
if not commit:
return {"ref": None, "url": None}
short = commit if len(commit) <= 12 else commit[:7]
return {
"ref": short,
"url": f"{REPO_URL}/commit/{commit}",
}