# ── Stage 1: build (has compiler for any source builds) ────────── FROM python:3.11-slim AS builder RUN apt-get update && apt-get install -y --no-install-recommends \ libgeos-dev \ libproj-dev \ proj-data \ proj-bin \ g++ \ && rm -rf /var/lib/apt/lists/* # Install heavy scientific deps as binary wheels where possible # Cartopy has no ARM wheel so it compiles from source on Mac but uses # a pre-built wheel on HF Spaces (x86_64) RUN pip install --no-cache-dir --only-binary :all: \ numpy scipy matplotlib geopandas shapely pyproj rioxarray xarray \ && pip install --no-cache-dir --prefer-binary cartopy # Pre-download 50m Natural Earth data; non-fatal if download fails RUN mkdir -p /root/.local/share/cartopy && \ python -c "import cartopy.io.shapereader as s; [s.natural_earth(resolution='50m', category=c, name=n) for c, n in [('physical','land'),('physical','ocean'),('physical','coastline'),('cultural','admin_0_boundary_lines_lake')]]" \ || echo "Natural Earth download skipped — Cartopy will use defaults" # Install remaining deps (lightweight, pure-python or small wheels) RUN pip install --no-cache-dir --prefer-binary \ "fastapi>=0.110.0" \ "uvicorn[standard]>=0.27.0" \ "aiosqlite>=0.20.0" \ "pydantic>=2.6.0" \ "httpx>=0.27.0" \ "pystac-client>=0.7.0" \ "stackstac>=0.5.0" \ "reportlab>=4.1.0" \ "tqdm>=4.66.0" \ "planetary-computer>=1.0.0" \ "openeo>=0.28.0" \ "anthropic>=0.40.0" \ "rasterio>=1.3.0" # ── Stage 2: runtime (no compiler, smaller image) ─────────────── FROM python:3.11-slim RUN apt-get update && apt-get install -y --no-install-recommends \ libgeos-c1v5 \ libproj25 \ libexpat1 \ proj-data \ proj-bin \ && rm -rf /var/lib/apt/lists/* # Copy installed packages from builder COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages COPY --from=builder /usr/local/bin /usr/local/bin COPY --from=builder /root/.local/share/cartopy /root/.local/share/cartopy WORKDIR /app # Install app package (no-deps, just makes app/ importable) COPY pyproject.toml . COPY app/ app/ RUN pip install --no-cache-dir --no-deps . COPY frontend/ frontend/ RUN mkdir -p data results EXPOSE 7860 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]