Dockerfile 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. FROM python:3.12-slim AS builder
  2. # Install system dependencies
  3. RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
  4. RUN sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
  5. # 在 builder 和 final stage 的 RUN apt-get update 前,可以尝试更彻底的替换
  6. RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
  7. echo "deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware" > /etc/apt/sources.list && \
  8. echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware" >> /etc/apt/sources.list && \
  9. echo "deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware" >> /etc/apt/sources.list && \
  10. echo "deb https://mirrors.aliyun.com/debian-security bookworm-security main non-free non-free-firmware" >> /etc/apt/sources.list
  11. RUN apt-get update && apt-get install -y --no-install-recommends \
  12. gcc g++ musl-dev curl libffi-dev gfortran libopenblas-dev \
  13. poppler-utils \
  14. && apt-get clean && rm -rf /var/lib/apt/lists/* \
  15. && curl --proto '=https' --tlsv1.2 --http1.1 -sSf https://mirrors.ustc.edu.cn/rust-static/rustup/rustup-init.sh | sh -s -- -y
  16. # && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
  17. # Add Rust to PATH
  18. ENV PATH="/root/.cargo/bin:${PATH}"
  19. # Create the /app/py directory
  20. RUN mkdir -p /app/py
  21. WORKDIR /app/py
  22. COPY pyproject.toml ./
  23. RUN pip install -e ".[core]" && \
  24. pip install gunicorn uvicorn pydantic
  25. # Optionally, if you want gunicorn and uvicorn explicitly installed, you can
  26. # either list them under [project] in `pyproject.toml` or install them here:
  27. RUN pip install --no-cache-dir gunicorn uvicorn
  28. # Create the final image
  29. FROM python:3.12-slim
  30. RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
  31. RUN sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
  32. # 在 builder 和 final stage 的 RUN apt-get update 前,可以尝试更彻底的替换
  33. RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak && \
  34. echo "deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware" > /etc/apt/sources.list && \
  35. echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware" >> /etc/apt/sources.list && \
  36. echo "deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware" >> /etc/apt/sources.list && \
  37. echo "deb https://mirrors.aliyun.com/debian-security bookworm-security main non-free non-free-firmware" >> /etc/apt/sources.list
  38. # Minimal runtime deps
  39. RUN apt-get update && apt-get install -y --no-install-recommends \
  40. curl poppler-utils \
  41. && apt-get clean && rm -rf /var/lib/apt/lists/*
  42. # Copy the built environment from builder to final image
  43. # (If you want a fully self-contained environment, copy /usr/local)
  44. COPY --from=builder /usr/local /usr/local
  45. WORKDIR /app
  46. # Copy the rest of your source code
  47. COPY . /app
  48. # Expose environment variables and port
  49. ARG R2R_PORT=8000 R2R_HOST=0.0.0.0
  50. ENV R2R_PORT=$R2R_PORT R2R_HOST=$R2R_HOST
  51. EXPOSE $R2R_PORT
  52. # Launch the app
  53. CMD ["sh", "-c", "uvicorn core.main.app_entry:app --host $R2R_HOST --port $R2R_PORT"]