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.
This commit is contained in:
parent
c0826e1a36
commit
89cdeb0967
@ -15,6 +15,7 @@ WORKDIR /app
|
|||||||
ENV UV_COMPILE_BYTECODE=1
|
ENV UV_COMPILE_BYTECODE=1
|
||||||
ENV PATH="/app/.venv/bin:$PATH"
|
ENV PATH="/app/.venv/bin:$PATH"
|
||||||
ENV MPLCONFIGDIR=/tmp/matplotlib
|
ENV MPLCONFIGDIR=/tmp/matplotlib
|
||||||
|
ENV MCNOAA_CHARTS_DIR=/tmp/charts
|
||||||
|
|
||||||
COPY --from=deps /app/.venv /app/.venv
|
COPY --from=deps /app/.venv /app/.venv
|
||||||
COPY src/ src/
|
COPY src/ src/
|
||||||
|
|||||||
@ -189,9 +189,17 @@ def register(mcp: FastMCP) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def _save_html(html: str, station_id: str, chart_type: str) -> Path:
|
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")
|
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)
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
path = out_dir / f"{station_id}_{chart_type}_{timestamp}.html"
|
path = out_dir / f"{station_id}_{chart_type}_{timestamp}.html"
|
||||||
path.write_text(html, encoding="utf-8")
|
path.write_text(html, encoding="utf-8")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user