FROM python:3.12-slim

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev tesseract-ocr tesseract-ocr-eng && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir --upgrade pip

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

RUN adduser --disabled-password --no-create-home appuser
RUN mkdir -p /app/storage && chown -R appuser /app/storage

COPY --chown=appuser app/ app/

ENV PYTHONUNBUFFERED=1

USER appuser
CMD ["rq", "worker", "brain", "--url", "redis://brain-redis:6379/0", "--path", "/app"]
