diff --git a/Makefile b/Makefile index 5190434..48938ac 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,11 @@ web-debug: $(PYTHON) FLASK_DEBUG=1 $(PYTHON) app.py image: - docker build -t fuj-management:latest -f build/Dockerfile . + docker build -t fuj-management:latest \ + --build-arg GIT_TAG=$$(git describe --tags --always 2>/dev/null || echo "untagged") \ + --build-arg GIT_COMMIT=$$(git rev-parse --short HEAD) \ + --build-arg BUILD_DATE=$$(date -u +%Y-%m-%dT%H:%M:%SZ) \ + -f build/Dockerfile . run: docker run -it --rm -p 5001:5001 -v $(CURDIR)/.secret:/app/.secret:ro fuj-management:latest diff --git a/app.py b/app.py index c52ccde..7d5a524 100644 --- a/app.py +++ b/app.py @@ -72,6 +72,13 @@ def warmup_cache(): logger.info("Cache warmup complete.") app = Flask(__name__) + +import json as _json +_meta_path = Path(__file__).parent / "build_meta.json" +BUILD_META = _json.loads(_meta_path.read_text()) if _meta_path.exists() else { + "tag": "dev", "commit": "local", "build_date": "" +} + warmup_cache() @app.before_request @@ -101,7 +108,7 @@ def inject_render_time(): "total": f"{total:.3f}", "breakdown": " | ".join(breakdown) } - return dict(get_render_time=get_render_time) + return dict(get_render_time=get_render_time, build_meta=BUILD_META) @app.route("/") def index(): @@ -113,6 +120,10 @@ def flush_cache_endpoint(): deleted = flush_cache() return jsonify({"status": "ok", "deleted_files": deleted}) +@app.route("/version") +def version(): + return BUILD_META + @app.route("/fees") def fees(): attendance_url = f"https://docs.google.com/spreadsheets/d/{ATTENDANCE_SHEET_ID}/edit" diff --git a/build/Dockerfile b/build/Dockerfile index d5db664..d5e7438 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -24,6 +24,17 @@ COPY templates/ ./templates/ COPY build/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh +ARG GIT_TAG=unknown +ARG GIT_COMMIT=unknown +ARG BUILD_DATE=unknown + +LABEL org.opencontainers.image.version="${GIT_TAG}" \ + org.opencontainers.image.revision="${GIT_COMMIT}" \ + org.opencontainers.image.created="${BUILD_DATE}" \ + org.opencontainers.image.title="fuj-management" + +RUN echo "{\"tag\": \"${GIT_TAG}\", \"commit\": \"${GIT_COMMIT}\", \"build_date\": \"${BUILD_DATE}\"}" > /app/build_meta.json + EXPOSE 5001 HEALTHCHECK --interval=60s --timeout=5s --start-period=5s \ diff --git a/templates/adults.html b/templates/adults.html index f48eae0..0420116 100644 --- a/templates/adults.html +++ b/templates/adults.html @@ -647,7 +647,7 @@ {% set rt = get_render_time() %}