# ============================================================
# LangChain Tool-Calling Starter — Dockerfile
# Builds a lightweight image that serves the FastAPI endpoint.
# ============================================================

FROM python:3.11-slim

# Metadata
LABEL maintainer="DemIA Living Lab — USAL/BISITE"
LABEL description="LangChain Tool-Calling Starter"

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

# Create non-root user for security
RUN useradd --create-home --shell /bin/bash appuser

WORKDIR /app

# Install Python dependencies first (cached layer)
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
    && pip install --no-cache-dir -r requirements.txt

# Copy source code
COPY config/ ./config/
COPY src/ ./src/
COPY api/ ./api/
COPY app/ ./app/

# Change ownership to non-root user
RUN chown -R appuser:appuser /app
USER appuser

# Expose FastAPI port
EXPOSE 8000

# Health-check: ensure the /health endpoint responds
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
    CMD curl -f http://localhost:8000/health || exit 1

# Default command: start the FastAPI server
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"]
