Dockerfile 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. FROM python:3.12-slim AS builder
  2. # 修改APT源为传入的镜像
  3. #RUN apt-get update && apt-get install -y gnupg2
  4. #RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3B4FE6ACC0B21F32 871920D1991BC93C
  5. # Install system dependencies
  6. RUN apt-get update && apt-get install -y --no-install-recommends \
  7. gcc g++ musl-dev curl libffi-dev gfortran libopenblas-dev \
  8. poppler-utils \
  9. && apt-get clean && rm -rf /var/lib/apt/lists/*
  10. RUN pip install --no-cache-dir poetry -i https://pypi.tuna.tsinghua.edu.cn/simple
  11. RUN poetry init
  12. # Add Rust to PATH
  13. ENV PATH="/root/.cargo/bin:${PATH}"
  14. RUN mkdir -p /app/py
  15. WORKDIR /app/py
  16. COPY pyproject.toml /app/py/pyproject.toml
  17. #RUN poetry config repositories.pypi https://mirrors.aliyun.com/pypi/simple/
  18. #RUN export POETRY_PYPI_REPOSITORIES="https://pypi.tuna.tsinghua.edu.cn/simple"
  19. # Install dependencies
  20. RUN poetry config virtualenvs.create false \
  21. && poetry install --extras "core ingestion-bundle" --only main --no-root \
  22. && pip install --no-cache-dir gunicorn uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple
  23. # Create the final image
  24. FROM python:3.12-slim
  25. # Install runtime dependencies
  26. RUN apt-get update \
  27. && apt-get install -y --no-install-recommends curl poppler-utils \
  28. && apt-get clean && rm -rf /var/lib/apt/lists/*
  29. # Add poppler to PATH
  30. ENV PATH="/usr/bin:${PATH}"
  31. # Debugging steps
  32. RUN echo "PATH: $PATH"
  33. RUN which pdfinfo
  34. RUN pdfinfo -v
  35. WORKDIR /app
  36. COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
  37. COPY --from=builder /usr/local/bin /usr/local/bin
  38. # Expose the port and set environment variables
  39. ARG R2R_PORT=8000 R2R_HOST=0.0.0.0
  40. ENV R2R_PORT=$R2R_PORT R2R_HOST=$R2R_HOST
  41. EXPOSE $R2R_PORT
  42. COPY . /app
  43. # Copy the application and config
  44. COPY core /app/core
  45. COPY r2r /app/r2r
  46. COPY shared /app/shared
  47. COPY r2r.toml /app/r2r.toml
  48. COPY pyproject.toml /app/pyproject.toml
  49. # Run the application
  50. CMD ["sh", "-c", "uvicorn core.main.app_entry:app --host $R2R_HOST --port $R2R_PORT"]