Root cause: Dockerfile build context is ./app/ but VERSION file is at repo root, so it's excluded from the Docker image. The context processor tried parent.parent.parent which resolves to / inside the container. Fix: - Context processor now checks APP_VERSION env var first, then tries multiple file paths (repo root for local dev, app/ dir for Docker) - Dockerfile accepts APP_VERSION build arg and sets it as ENV - compose.yml passes APP_VERSION build arg to all service builds Note: Deploy script needs `export APP_VERSION=$(cat VERSION)` before docker-compose build for the build arg to pick up the version. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
27 lines
838 B
Python
27 lines
838 B
Python
import os
|
|
from pathlib import Path
|
|
|
|
_VERSION = None
|
|
|
|
|
|
def app_version(request):
|
|
global _VERSION
|
|
if _VERSION is None:
|
|
# 1. Environment variable (set in Docker/deployment)
|
|
_VERSION = os.environ.get("APP_VERSION", "").strip()
|
|
if not _VERSION:
|
|
# 2. Try VERSION file at common locations
|
|
base = Path(__file__).resolve().parent.parent # app/
|
|
for candidate in [
|
|
base.parent / "VERSION", # repo root (local dev)
|
|
base / "VERSION", # app/ dir (Docker)
|
|
]:
|
|
try:
|
|
_VERSION = candidate.read_text().strip()
|
|
break
|
|
except FileNotFoundError:
|
|
continue
|
|
else:
|
|
_VERSION = "unknown"
|
|
return {"APP_VERSION": _VERSION}
|