Dockerfile 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. # Add Rust to PATH
  12. ENV PATH="/root/.cargo/bin:${PATH}"
  13. RUN mkdir -p /app/py
  14. WORKDIR /app/py
  15. COPY pyproject.toml /app/py/pyproject.toml
  16. #RUN poetry config repositories.pypi https://mirrors.aliyun.com/pypi/simple/
  17. #RUN export POETRY_PYPI_REPOSITORIES="https://pypi.tuna.tsinghua.edu.cn/simple"
  18. # Install dependencies
  19. RUN poetry config virtualenvs.create false \
  20. && poetry install --extras "core ingestion-bundle" --only main --no-root \
  21. && pip install --no-cache-dir gunicorn uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple
  22. # Create the final image
  23. FROM python:3.12-slim
  24. # Install runtime dependencies
  25. RUN apt-get update \
  26. && apt-get install -y --no-install-recommends curl poppler-utils \
  27. && apt-get clean && rm -rf /var/lib/apt/lists/*
  28. # Add poppler to PATH
  29. ENV PATH="/usr/bin:${PATH}"
  30. # Debugging steps
  31. RUN echo "PATH: $PATH"
  32. RUN which pdfinfo
  33. RUN pdfinfo -v
  34. WORKDIR /app
  35. COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
  36. COPY --from=builder /usr/local/bin /usr/local/bin
  37. # Expose the port and set environment variables
  38. ARG R2R_PORT=8000 R2R_HOST=0.0.0.0
  39. ENV R2R_PORT=$R2R_PORT R2R_HOST=$R2R_HOST
  40. EXPOSE $R2R_PORT
  41. COPY . /app
  42. # Copy the application and config
  43. COPY core /app/core
  44. COPY r2r /app/r2r
  45. COPY shared /app/shared
  46. COPY r2r.toml /app/r2r.toml
  47. COPY pyproject.toml /app/pyproject.toml
  48. # Run the application
  49. CMD ["sh", "-c", "uvicorn core.main.app_entry:app --host $R2R_HOST --port $R2R_PORT"]