Dockerfile 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. FROM python:3.12-slim AS builder
  2. # Install system dependencies
  3. RUN apt-get update && apt-get install -y --no-install-recommends \
  4. gcc g++ musl-dev curl libffi-dev gfortran libopenblas-dev \
  5. poppler-utils \
  6. && apt-get clean && rm -rf /var/lib/apt/lists/* \
  7. && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
  8. # Add Rust to PATH
  9. ENV PATH="/root/.cargo/bin:${PATH}"
  10. # Create the /app/py directory
  11. RUN mkdir -p /app/py
  12. WORKDIR /app/py
  13. COPY pyproject.toml ./
  14. RUN pip install --default-timeout=1000 -i https://pypi.tuna.tsinghua.edu.cn/simple/ -e ".[core]" && \
  15. pip install gunicorn uvicorn pydantic
  16. # Optionally, if you want gunicorn and uvicorn explicitly installed, you can
  17. # either list them under [project] in `pyproject.toml` or install them here:
  18. RUN pip install --no-cache-dir gunicorn uvicorn
  19. # Create the final image
  20. FROM python:3.12-slim
  21. # Minimal runtime deps
  22. RUN apt-get update && apt-get install -y --no-install-recommends \
  23. curl poppler-utils \
  24. && apt-get clean && rm -rf /var/lib/apt/lists/*
  25. # Copy the built environment from builder to final image
  26. # (If you want a fully self-contained environment, copy /usr/local)
  27. COPY --from=builder /usr/local /usr/local
  28. WORKDIR /app
  29. # Copy the rest of your source code
  30. COPY . /app
  31. # Expose environment variables and port
  32. ARG R2R_PORT=8000 R2R_HOST=0.0.0.0
  33. ENV R2R_PORT=$R2R_PORT R2R_HOST=$R2R_HOST
  34. EXPOSE $R2R_PORT
  35. # Launch the app
  36. CMD ["sh", "-c", "uvicorn core.main.app_entry:app --host $R2R_HOST --port $R2R_PORT --workers 40"]