4 Commits
0.19 ... 0.23

Author SHA1 Message Date
3ad4a21f5b feat: Pass build metadata args in Gitea CI pipeline
Some checks failed
Deploy to K8s / deploy (push) Failing after 6s
Build and Push / build (push) Successful in 5s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 16:34:34 +01:00
3c1604c7af feat: Bake build metadata (git tag, commit, date) into OCI image and display in web UI
Some checks failed
Deploy to K8s / deploy (push) Failing after 10s
Build and Push / build (push) Successful in 6s
Store git tag, commit hash, and build date as OCI-standard labels and a
build_meta.json file inside the Docker image. The Flask app reads this at
startup and displays version info in all page footers. Adds /version JSON
endpoint for programmatic access. Falls back to dev@local outside Docker.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 16:30:20 +01:00
8b3223f865 feat: Add POST /flush-cache endpoint to clear all cached data and reset timers
Some checks failed
Deploy to K8s / deploy (push) Failing after 7s
Build and Push / build (push) Successful in 6s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 10:45:47 +01:00
276e18a9c8 feat: Show attendance breakdown for single-visit junior fees
All checks were successful
Build and Push / build (push) Successful in 8s
When a junior attended only once in a month (fee = "?"), the dashboard
cells now display the attendance details (e.g., "? (1:1J)") instead of
a bare "?". Applied to both /juniors and /reconcile-juniors routes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 10:41:45 +01:00
12 changed files with 86 additions and 16 deletions

View File

@@ -31,5 +31,9 @@ jobs:
TAG=${{ inputs.tag }} TAG=${{ inputs.tag }}
fi fi
IMAGE=gitea.home.hrajfrisbee.cz/${{ github.repository }}:$TAG IMAGE=gitea.home.hrajfrisbee.cz/${{ github.repository }}:$TAG
docker build -f build/Dockerfile -t $IMAGE . docker build -f build/Dockerfile \
--build-arg GIT_TAG=$TAG \
--build-arg GIT_COMMIT=${{ github.sha }} \
--build-arg BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
-t $IMAGE .
docker push $IMAGE docker push $IMAGE

View File

@@ -45,7 +45,11 @@ web-debug: $(PYTHON)
FLASK_DEBUG=1 $(PYTHON) app.py FLASK_DEBUG=1 $(PYTHON) app.py
image: 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: run:
docker run -it --rm -p 5001:5001 -v $(CURDIR)/.secret:/app/.secret:ro fuj-management:latest docker run -it --rm -p 5001:5001 -v $(CURDIR)/.secret:/app/.secret:ro fuj-management:latest

49
app.py
View File

@@ -7,7 +7,7 @@ import os
import io import io
import qrcode import qrcode
import logging import logging
from flask import Flask, render_template, g, send_file, request from flask import Flask, render_template, g, send_file, request, jsonify
# Configure logging, allowing override via LOG_LEVEL environment variable # Configure logging, allowing override via LOG_LEVEL environment variable
log_level = os.environ.get("LOG_LEVEL", "INFO").upper() log_level = os.environ.get("LOG_LEVEL", "INFO").upper()
@@ -23,7 +23,7 @@ from config import (
) )
from attendance import get_members_with_fees, get_junior_members_with_fees, ADULT_MERGED_MONTHS, JUNIOR_MERGED_MONTHS from attendance import get_members_with_fees, get_junior_members_with_fees, ADULT_MERGED_MONTHS, JUNIOR_MERGED_MONTHS
from match_payments import reconcile, fetch_sheet_data, fetch_exceptions, normalize from match_payments import reconcile, fetch_sheet_data, fetch_exceptions, normalize
from cache_utils import get_sheet_modified_time, read_cache, write_cache, _LAST_CHECKED from cache_utils import get_sheet_modified_time, read_cache, write_cache, _LAST_CHECKED, flush_cache
def get_cached_data(cache_key, sheet_id, fetch_func, *args, serialize=None, deserialize=None, **kwargs): def get_cached_data(cache_key, sheet_id, fetch_func, *args, serialize=None, deserialize=None, **kwargs):
mod_time = get_sheet_modified_time(cache_key) mod_time = get_sheet_modified_time(cache_key)
@@ -72,6 +72,13 @@ def warmup_cache():
logger.info("Cache warmup complete.") logger.info("Cache warmup complete.")
app = Flask(__name__) 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() warmup_cache()
@app.before_request @app.before_request
@@ -101,13 +108,22 @@ def inject_render_time():
"total": f"{total:.3f}", "total": f"{total:.3f}",
"breakdown": " | ".join(breakdown) "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("/") @app.route("/")
def index(): def index():
# Redirect root to /adults for convenience while there are no other apps # Redirect root to /adults for convenience while there are no other apps
return '<meta http-equiv="refresh" content="0; url=/adults" />' return '<meta http-equiv="refresh" content="0; url=/adults" />'
@app.route("/flush-cache", methods=["POST"])
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") @app.route("/fees")
def fees(): def fees():
attendance_url = f"https://docs.google.com/spreadsheets/d/{ATTENDANCE_SHEET_ID}/edit" attendance_url = f"https://docs.google.com/spreadsheets/d/{ATTENDANCE_SHEET_ID}/edit"
@@ -582,7 +598,7 @@ def juniors_view():
if expected == "?" or (isinstance(expected, int) and expected > 0): if expected == "?" or (isinstance(expected, int) and expected > 0):
if expected == "?": if expected == "?":
status = "empty" status = "empty"
cell_text = "?" cell_text = f"?{count_str}"
elif paid >= expected: elif paid >= expected:
status = "ok" status = "ok"
cell_text = f"{paid}/{fee_display}" cell_text = f"{paid}/{fee_display}"
@@ -705,6 +721,8 @@ def reconcile_juniors_view():
# Filter to juniors for the main table # Filter to juniors for the main table
junior_names = sorted([name for name, tier, _ in adapted_members]) junior_names = sorted([name for name, tier, _ in adapted_members])
junior_members_dict_rc = {name: fees_dict for name, _, fees_dict in junior_members}
formatted_results = [] formatted_results = []
for name in junior_names: for name in junior_names:
data = result["members"][name] data = result["members"][name]
@@ -714,15 +732,32 @@ def reconcile_juniors_view():
mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "paid": 0}) mdata = data["months"].get(m, {"expected": 0, "original_expected": 0, "paid": 0})
expected = mdata["expected"] expected = mdata["expected"]
paid = int(mdata["paid"]) paid = int(mdata["paid"])
orig_fee_data = junior_members_dict_rc.get(name, {}).get(m)
adult_count = 0
junior_count = 0
att_count = 0
if orig_fee_data and len(orig_fee_data) == 4:
_, att_count, adult_count, junior_count = orig_fee_data
breakdown = ""
if adult_count > 0 and junior_count > 0:
breakdown = f":{junior_count}J,{adult_count}A"
elif junior_count > 0:
breakdown = f":{junior_count}J"
elif adult_count > 0:
breakdown = f":{adult_count}A"
count_str = f" ({att_count}{breakdown})" if att_count > 0 else ""
status = "empty" status = "empty"
cell_text = "-" cell_text = "-"
amount_to_pay = 0 amount_to_pay = 0
if expected == "?" or (isinstance(expected, int) and expected > 0): if expected == "?" or (isinstance(expected, int) and expected > 0):
if expected == "?": if expected == "?":
status = "empty" status = "empty"
cell_text = "?" cell_text = f"?{count_str}"
elif paid >= expected: elif paid >= expected:
status = "ok" status = "ok"
cell_text = "OK" cell_text = "OK"

View File

@@ -24,6 +24,17 @@ COPY templates/ ./templates/
COPY build/entrypoint.sh /entrypoint.sh COPY build/entrypoint.sh /entrypoint.sh
RUN chmod +x /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 EXPOSE 5001
HEALTHCHECK --interval=60s --timeout=5s --start-period=5s \ HEALTHCHECK --interval=60s --timeout=5s --start-period=5s \

View File

@@ -155,3 +155,19 @@ def write_cache(sheet_id: str, modified_time: str, data: list | dict) -> None:
logger.info(f"Wrote cache for {sheet_id}") logger.info(f"Wrote cache for {sheet_id}")
except Exception as e: except Exception as e:
logger.error(f"Failed to write cache {sheet_id}: {e}") logger.error(f"Failed to write cache {sheet_id}: {e}")
def flush_cache():
"""Delete all cache files and reset in-memory state. Returns count of deleted files."""
global _DRIVE_SERVICE
_LAST_CHECKED.clear()
_DRIVE_SERVICE = None
deleted = 0
if CACHE_DIR.exists():
for f in CACHE_DIR.glob("*_cache.json"):
f.unlink()
deleted += 1
logger.info(f"Deleted cache file: {f.name}")
logger.info(f"Cache flushed: {deleted} files deleted, timers reset")
return deleted

View File

@@ -647,7 +647,7 @@
{% set rt = get_render_time() %} {% set rt = get_render_time() %}
<div class="footer" <div class="footer"
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')"> onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
render time: {{ rt.total }}s {{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
<div id="perf-details" class="perf-breakdown"> <div id="perf-details" class="perf-breakdown">
{{ rt.breakdown }} {{ rt.breakdown }}
</div> </div>

View File

@@ -238,7 +238,7 @@
{% set rt = get_render_time() %} {% set rt = get_render_time() %}
<div class="footer" <div class="footer"
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')"> onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
render time: {{ rt.total }}s {{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
<div id="perf-details" class="perf-breakdown"> <div id="perf-details" class="perf-breakdown">
{{ rt.breakdown }} {{ rt.breakdown }}
</div> </div>

View File

@@ -253,7 +253,7 @@
{% set rt = get_render_time() %} {% set rt = get_render_time() %}
<div class="footer" <div class="footer"
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')"> onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
render time: {{ rt.total }}s {{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
<div id="perf-details" class="perf-breakdown"> <div id="perf-details" class="perf-breakdown">
{{ rt.breakdown }} {{ rt.breakdown }}
</div> </div>

View File

@@ -628,7 +628,7 @@
{% set rt = get_render_time() %} {% set rt = get_render_time() %}
<div class="footer" <div class="footer"
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')"> onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
render time: {{ rt.total }}s {{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
<div id="perf-details" class="perf-breakdown"> <div id="perf-details" class="perf-breakdown">
{{ rt.breakdown }} {{ rt.breakdown }}
</div> </div>

View File

@@ -237,7 +237,7 @@
{% set rt = get_render_time() %} {% set rt = get_render_time() %}
<div class="footer" <div class="footer"
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')"> onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
render time: {{ rt.total }}s {{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
<div id="perf-details" class="perf-breakdown"> <div id="perf-details" class="perf-breakdown">
{{ rt.breakdown }} {{ rt.breakdown }}
</div> </div>

View File

@@ -631,7 +631,7 @@
{% set rt = get_render_time() %} {% set rt = get_render_time() %}
<div class="footer" <div class="footer"
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')"> onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
render time: {{ rt.total }}s {{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
<div id="perf-details" class="perf-breakdown"> <div id="perf-details" class="perf-breakdown">
{{ rt.breakdown }} {{ rt.breakdown }}
</div> </div>

View File

@@ -631,7 +631,7 @@
{% set rt = get_render_time() %} {% set rt = get_render_time() %}
<div class="footer" <div class="footer"
onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')"> onclick="document.getElementById('perf-details').style.display = (document.getElementById('perf-details').style.display === 'block' ? 'none' : 'block')">
render time: {{ rt.total }}s {{ build_meta.tag }}@{{ build_meta.commit }} | render time: {{ rt.total }}s
<div id="perf-details" class="perf-breakdown"> <div id="perf-details" class="perf-breakdown">
{{ rt.breakdown }} {{ rt.breakdown }}
</div> </div>