# ── Keras Regression Starter — Dockerfile ─────────────────────────────────────
# Builds a container that trains the model on startup and exposes the REST API.
#
# Build:
#   docker build -t keras-regression-starter .
#
# Run (train + serve):
#   docker run -p 8000:8000 keras-regression-starter
#
# Run (serve only, mount pre-trained models):
#   docker run -p 8000:8000 -v $(pwd)/models:/app/models keras-regression-starter serve

FROM python:3.11-slim

# Metadata
LABEL maintainer="DemIA Living Lab - Universidad de Salamanca (USAL) / BISITE"
LABEL description="Keras regression training pipeline"

# Prevent Python from writing .pyc files and buffer stdout/stderr.
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# TF log verbosity (suppress excessive TF C++ info messages).
ENV TF_CPP_MIN_LOG_LEVEL=2

WORKDIR /app

# Install OS dependencies (minimal set needed by TensorFlow on slim images).
RUN apt-get update && apt-get install -y --no-install-recommends \
        libgomp1 \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies.
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy project source.
COPY src/ ./src/
COPY api/ ./api/
COPY config/ ./config/
COPY scripts/ ./scripts/
COPY .env.example .env

# Create directories for model artefacts and logs.
RUN mkdir -p models logs

# Expose the FastAPI port.
EXPOSE 8000

# Default: train then start the API server.
# Override CMD to run a different sub-command, e.g. ["python", "scripts/run.py", "evaluate"]
CMD ["sh", "-c", "python scripts/run.py train && uvicorn api.main:app --host 0.0.0.0 --port 8000"]
