Add build version indicator to sidebar menu
Display commit date and short hash (e.g., "2026-01-08 fb59ef7") below the ANIMALTRACK title in the sidebar. In development, reads from git directly; in Docker, reads from BUILD_DATE/BUILD_COMMIT env vars injected at build time from the Nix flake. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{ pkgs, pythonEnv, python }:
|
||||
{ pkgs, pythonEnv, python, buildDate ? "unknown", buildCommit ? "unknown" }:
|
||||
|
||||
let
|
||||
# Build animaltrack as a package
|
||||
@@ -59,6 +59,8 @@ pkgs.dockerTools.buildImage {
|
||||
"PATH=${pkgs.lib.makeBinPath [ pkgs.busybox pkgs.bash pkgs.sqlite pythonEnv animaltrack ]}"
|
||||
"PYTHONPATH=${pythonEnv}/${pythonEnv.sitePackages}:${animaltrack}/${pythonEnv.sitePackages}"
|
||||
"PYTHONUNBUFFERED=1"
|
||||
"BUILD_DATE=${buildDate}"
|
||||
"BUILD_COMMIT=${buildCommit}"
|
||||
];
|
||||
ExposedPorts = {
|
||||
"5000/tcp" = {};
|
||||
|
||||
@@ -67,7 +67,12 @@
|
||||
in
|
||||
{
|
||||
packages.${system} = {
|
||||
dockerImage = import ./docker.nix { inherit pkgs pythonEnv python; };
|
||||
dockerImage = let
|
||||
buildDate = let
|
||||
d = self.lastModifiedDate or "00000000000000";
|
||||
in "${builtins.substring 0 4 d}-${builtins.substring 4 2 d}-${builtins.substring 6 2 d}";
|
||||
buildCommit = self.shortRev or self.dirtyShortRev or "unknown";
|
||||
in import ./docker.nix { inherit pkgs pythonEnv python buildDate buildCommit; };
|
||||
};
|
||||
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
|
||||
34
src/animaltrack/build_info.py
Normal file
34
src/animaltrack/build_info.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# ABOUTME: Provides build information (date + commit hash) for version display.
|
||||
# ABOUTME: Reads from env vars (Docker) or git (development).
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def get_build_info() -> str:
|
||||
"""Returns build info in '2025-01-08 fb59ef7' format.
|
||||
|
||||
Checks BUILD_DATE and BUILD_COMMIT env vars first (set by Docker),
|
||||
then falls back to reading git info at runtime (development).
|
||||
Returns 'unknown' if neither source is available.
|
||||
"""
|
||||
build_date = os.environ.get("BUILD_DATE")
|
||||
build_commit = os.environ.get("BUILD_COMMIT")
|
||||
|
||||
if build_date and build_commit:
|
||||
return f"{build_date} {build_commit}"
|
||||
|
||||
# Try git at runtime (development mode)
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["git", "log", "-1", "--format=%cs %h"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5,
|
||||
)
|
||||
if result.returncode == 0 and result.stdout.strip():
|
||||
return result.stdout.strip()
|
||||
except (subprocess.SubprocessError, FileNotFoundError, OSError):
|
||||
pass
|
||||
|
||||
return "unknown"
|
||||
@@ -4,6 +4,7 @@
|
||||
from fasthtml.common import A, Button, Div, Nav, Script, Span, Style
|
||||
from fasthtml.svg import Path, Svg
|
||||
|
||||
from animaltrack.build_info import get_build_info
|
||||
from animaltrack.models.reference import UserRole
|
||||
from animaltrack.web.templates.icons import EggIcon, FeedIcon, MoveIcon
|
||||
|
||||
@@ -213,7 +214,8 @@ def Sidebar( # noqa: N802
|
||||
return Nav(
|
||||
# Logo/Brand
|
||||
Div(
|
||||
Span("ANIMALTRACK", cls="text-amber-600 font-bold tracking-wider text-sm"),
|
||||
Div("ANIMALTRACK", cls="text-amber-600 font-bold tracking-wider text-sm"),
|
||||
Div(get_build_info(), cls="text-stone-600 text-[10px] tracking-wide"),
|
||||
cls="px-4 py-4 border-b border-stone-800",
|
||||
),
|
||||
# Primary navigation
|
||||
|
||||
Reference in New Issue
Block a user