# ── TFLite Conversion Starter – Dockerfile ───────────────────────────────────
# Builds a minimal CPU image that can:
#   • Run the conversion pipeline  (default CMD)
#   • Serve the FastAPI inference API
#
# Build:
#   docker build -t tflite-conversion-starter .
#
# Run the end-to-end pipeline:
#   docker run --rm -v $(pwd)/outputs:/app/outputs tflite-conversion-starter
#
# Run the API server:
#   docker run --rm -p 8000:8000 \
#     -v $(pwd)/outputs:/app/outputs \
#     tflite-conversion-starter \
#     python scripts/run.py serve --host 0.0.0.0 --port 8000
# ─────────────────────────────────────────────────────────────────────────────

FROM python:3.11-slim

# Prevent .pyc files and enable unbuffered stdout/stderr.
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

WORKDIR /app

# ── System dependencies ───────────────────────────────────────────────────────
# libgomp is required by TensorFlow on some Linux builds.
RUN apt-get update && apt-get install -y --no-install-recommends \
        libgomp1 \
    && rm -rf /var/lib/apt/lists/*

# ── Python dependencies ───────────────────────────────────────────────────────
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# ── Application source ────────────────────────────────────────────────────────
COPY . .

# Ensure output directories exist inside the container.
RUN mkdir -p outputs/models outputs/tflite

# Copy example env file (actual secrets should be mounted or passed via --env).
RUN cp .env.example .env

# ── Expose API port ───────────────────────────────────────────────────────────
EXPOSE 8000

# ── Default: run the full pipeline (train → evaluate → convert) ───────────────
CMD ["python", "scripts/run.py", "pipeline"]
