From 89cdeb09679299e97840ca5061c9a431973b0a66 Mon Sep 17 00:00:00 2001 From: Ryan Malloy Date: Mon, 23 Feb 2026 19:46:29 -0700 Subject: [PATCH] Fix HTML chart output path for nobody container user Use MCNOAA_CHARTS_DIR env var (defaults to artifacts/charts/ for local dev) so the container's nobody user can write HTML charts to /tmp/charts instead of the read-only /app working directory. --- Dockerfile.mcp | 1 + src/mcnoaa_tides/tools/charts.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile.mcp b/Dockerfile.mcp index 5ca7746..f499316 100644 --- a/Dockerfile.mcp +++ b/Dockerfile.mcp @@ -15,6 +15,7 @@ WORKDIR /app ENV UV_COMPILE_BYTECODE=1 ENV PATH="/app/.venv/bin:$PATH" ENV MPLCONFIGDIR=/tmp/matplotlib +ENV MCNOAA_CHARTS_DIR=/tmp/charts COPY --from=deps /app/.venv /app/.venv COPY src/ src/ diff --git a/src/mcnoaa_tides/tools/charts.py b/src/mcnoaa_tides/tools/charts.py index b5775aa..3dbb5da 100644 --- a/src/mcnoaa_tides/tools/charts.py +++ b/src/mcnoaa_tides/tools/charts.py @@ -189,9 +189,17 @@ def register(mcp: FastMCP) -> None: def _save_html(html: str, station_id: str, chart_type: str) -> Path: - """Save HTML chart to artifacts/charts/ and return the path.""" + """Save HTML chart and return the path. + + Uses $MCNOAA_CHARTS_DIR if set, otherwise falls back to + artifacts/charts/ (relative to cwd). The container sets + MCNOAA_CHARTS_DIR=/tmp/charts so the nobody user can write. + """ + import os + timestamp = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S") - out_dir = Path("artifacts/charts") + base = os.environ.get("MCNOAA_CHARTS_DIR", "artifacts/charts") + out_dir = Path(base) out_dir.mkdir(parents=True, exist_ok=True) path = out_dir / f"{station_id}_{chart_type}_{timestamp}.html" path.write_text(html, encoding="utf-8")