Add automated build metadata generation system

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-07 19:37:40 +00:00
parent 6812d0d2c4
commit 5f175fabee
10 changed files with 562 additions and 27 deletions
+28
View File
@@ -213,6 +213,34 @@ class Settings(BaseSettings):
# Default version if not found
return "0.3.2-dev"
@property
def git_sha(self) -> str:
"""Get Git commit SHA from environment or file."""
# First try to get from environment
env_sha = os.environ.get("GIT_COMMIT_SHA")
if env_sha:
return env_sha
# Then try to get from GIT_SHA file
git_sha_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), "GIT_SHA")
if os.path.exists(git_sha_file):
with open(git_sha_file, "r") as f:
return f.read().strip()
# Default if not found
return "unknown"
@property
def runtime_info(self) -> str:
"""Get runtime information from file."""
runtime_info_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), "RUNTIME_INFO")
if os.path.exists(runtime_info_file):
with open(runtime_info_file, "r") as f:
return f.read().strip()
# Return basic info if file not found
return f"Version: {self.version}\nBuild Date: {self.build_date}\nGit SHA: {self.git_sha}"
class Config:
env_file = ".env"
+7 -24
View File
@@ -5,7 +5,6 @@ from fastapi import Request
from fastapi.responses import JSONResponse
from datetime import datetime
import os
import subprocess
import logging
from app.views.base import APIRouter, templates, require_login, settings
@@ -46,42 +45,26 @@ async def status_dashboard(request: Request):
except Exception:
container_info['id'] = 'Unknown'
# Try to get Git commit SHA from runtime info
# Get Git commit SHA from settings
try:
# First check runtime info directory
if os.path.exists('/app/runtime_info/GIT_SHA'):
with open('/app/runtime_info/GIT_SHA', 'r') as f:
git_sha = f.read().strip()
# Then try environment variable
else:
git_sha = os.environ.get('GIT_COMMIT_SHA', '')
# If still not found, try the original file location
if not git_sha and os.path.exists('/.git-commit-sha'):
with open('/.git-commit-sha', 'r') as f:
git_sha = f.read().strip()
git_sha = settings.git_sha
container_info['git_sha'] = git_sha[:7] if git_sha and git_sha != 'unknown' else 'Unknown'
except Exception:
container_info['git_sha'] = 'Unknown'
# Try to get runtime information
try:
if os.path.exists('/app/runtime_info/RUNTIME_INFO'):
with open('/app/runtime_info/RUNTIME_INFO', 'r') as f:
container_info['runtime_info'] = f.read().strip()
container_info['runtime_info'] = settings.runtime_info
except Exception:
pass
else:
container_info['is_docker'] = False
# If not in Docker, try to get Git info directly
# If not in Docker, get Git info from settings
try:
git_sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'],
stderr=subprocess.DEVNULL,
text=True).strip()[:7]
container_info['git_sha'] = git_sha
except (subprocess.SubprocessError, FileNotFoundError):
git_sha = settings.git_sha
container_info['git_sha'] = git_sha[:7] if git_sha and git_sha != 'unknown' else 'Unknown'
except Exception:
container_info['git_sha'] = 'Unknown'
except Exception:
container_info = {'is_docker': False, 'id': 'Unknown', 'git_sha': 'Unknown'}