# ── Stage 1: base image ──────────────────────────────────────
# Uses the official TensorFlow CPU image (no GPU drivers required).
# For GPU support swap the tag to e.g. tensorflow/tensorflow:2.15.0-gpu
FROM tensorflow/tensorflow:2.15.0 AS base

LABEL maintainer="DemIA Living Lab - USAL/BISITE <bisite@usal.es>"
LABEL description="U-Net image-segmentation pipeline — TensorFlow Segmentation Starter"

# System dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
        libgl1 \
        libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# ── Stage 2: install Python dependencies ─────────────────────
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
 && pip install --no-cache-dir -r requirements.txt

# ── Stage 3: copy application code ───────────────────────────
COPY config/ config/
COPY src/    src/
COPY api/    api/
COPY app/    app/
COPY scripts/ scripts/
COPY .env.example .env

# Create output directory for model weights / logs
RUN mkdir -p outputs logs

# Expose FastAPI port
EXPOSE 8000

# Default command: start the FastAPI inference service.
# Override with `docker run ... python scripts/run.py train` to train instead.
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"]
