# Dockerfile for svc_rag_retriever - Uses base-ml image
# Base image contains: FastAPI, database drivers, sentence-transformers, PyTorch, etc.
# This Dockerfile only adds service-specific dependencies and application code

ARG REGISTRY=gitea.harkon.co.uk
ARG OWNER=harkon
ARG BASE_VERSION=v1.0.1
FROM ${REGISTRY}/${OWNER}/base-ml:${BASE_VERSION}

# Switch to root to install service-specific dependencies
USER root

RUN apt-get update && apt-get install -y build-essential

# Set working directory
WORKDIR /app

# Copy service-specific requirements and install
COPY libs/requirements-base.txt /tmp/libs-requirements.txt
COPY apps/svc_rag_retriever/requirements.txt /tmp/service-requirements.txt
RUN pip install --no-cache-dir -r /tmp/libs-requirements.txt -r /tmp/service-requirements.txt

# Copy application code
COPY libs/ ./libs/
COPY apps/svc_rag_retriever/ ./apps/svc_rag_retriever/

# Set permissions and switch to non-root user
RUN chown -R appuser:appuser /app
USER appuser

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:8000/healthz || exit 1

# Expose port
EXPOSE 8000

# Run the application
CMD ["python", "-m", "uvicorn", "apps.svc_rag_retriever.main:app", "--host", "0.0.0.0", "--port", "8000"]
