Dockerfile 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. FROM python:3.10-slim-bookworm AS base
  2. WORKDIR /app
  3. ENV DEBIAN_FRONTEND=noninteractive \
  4. LANG=C.UTF-8 \
  5. PYTHONDONTWRITEBYTECODE=1 \
  6. PYTHONUNBUFFERED=1 \
  7. PIP_DISABLE_PIP_VERSION_CHECK=1 \
  8. PIP_NO_CACHE_DIR=1
  9. FROM base AS build
  10. # Update the package list and install necessary packages
  11. RUN apt-get update && \
  12. apt-get install -y --no-install-recommends \
  13. build-essential && \
  14. apt-get clean && \
  15. rm -rf /var/lib/apt/lists/*
  16. # Build Python dependencies
  17. COPY requirements.txt .
  18. RUN python -m venv /app/venv && \
  19. . /app/venv/bin/activate && \
  20. pip install -r requirements.txt && \
  21. pip uninstall -y paddlepaddle && \
  22. pip install -i https://www.paddlepaddle.org.cn/packages/stable/cu118/ \
  23. paddlepaddle-gpu==3.0.0rc1
  24. # Download models
  25. COPY download_models.py .
  26. RUN . /app/venv/bin/activate && \
  27. ./download_models.py
  28. FROM base AS prod
  29. # Copy Python dependencies and models from the build stage
  30. COPY --from=build /app/venv /app/venv
  31. COPY --from=build /opt/models /opt/models
  32. COPY --from=build /opt/layoutreader /opt/layoutreader
  33. # Update the package list and install necessary packages
  34. RUN apt-get update && \
  35. apt-get install -y --no-install-recommends \
  36. libgl1 \
  37. libglib2.0-0 \
  38. libgomp1 && \
  39. apt-get clean && \
  40. rm -rf /var/lib/apt/lists/*
  41. # Create volume for paddleocr models
  42. RUN mkdir -p /root/.paddleocr
  43. VOLUME [ "/root/.paddleocr" ]
  44. # Copy the app and its configuration file
  45. COPY entrypoint.sh /app/entrypoint.sh
  46. COPY magic-pdf.json /root/magic-pdf.json
  47. COPY app.py /app/app.py
  48. # Expose the port that FastAPI will run on
  49. EXPOSE 8000
  50. # Command to run FastAPI using Uvicorn, pointing to app.py and binding to 0.0.0.0:8000
  51. ENTRYPOINT [ "/app/entrypoint.sh" ]
  52. CMD ["--host", "0.0.0.0", "--port", "8000"]