Dockerfile 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # base image
  2. FROM python:3.12-slim-bookworm AS base
  3. WORKDIR /app/api
  4. # Install uv
  5. ENV UV_VERSION=0.8.14
  6. # RUN pip install --no-cache-dir uv==${UV_VERSION}
  7. # Using Tsinghua mirror for pip in China
  8. RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple uv==${UV_VERSION}
  9. FROM base AS packages
  10. # if you located in China, you can use aliyun mirror to speed up
  11. RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources
  12. RUN apt-get update \
  13. && apt-get install -y --no-install-recommends gcc g++ libc-dev libffi-dev libgmp-dev libmpfr-dev libmpc-dev
  14. # Install Python dependencies
  15. COPY pyproject.toml uv.lock ./
  16. #RUN uv sync --locked --no-dev
  17. # Using Tsinghua mirror for uv in China
  18. RUN uv sync --locked --no-dev --index-url https://pypi.tuna.tsinghua.edu.cn/simple
  19. # production stage
  20. FROM base AS production
  21. ENV FLASK_APP=app.py
  22. ENV EDITION=SELF_HOSTED
  23. ENV DEPLOY_ENV=PRODUCTION
  24. ENV CONSOLE_API_URL=http://127.0.0.1:5001
  25. ENV CONSOLE_WEB_URL=http://127.0.0.1:3000
  26. ENV SERVICE_API_URL=http://127.0.0.1:5001
  27. ENV APP_WEB_URL=http://127.0.0.1:3000
  28. EXPOSE 5001
  29. # set timezone
  30. ENV TZ=UTC
  31. # Set UTF-8 locale
  32. ENV LANG=en_US.UTF-8
  33. ENV LC_ALL=en_US.UTF-8
  34. ENV PYTHONIOENCODING=utf-8
  35. WORKDIR /app/api
  36. RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources
  37. RUN \
  38. apt-get update \
  39. # Install dependencies
  40. && apt-get install -y --no-install-recommends \
  41. # basic environment
  42. curl nodejs libgmp-dev libmpfr-dev libmpc-dev \
  43. # For Security
  44. expat libldap-2.5-0 perl libsqlite3-0 zlib1g \
  45. # install fonts to support the use of tools like pypdfium2
  46. fonts-noto-cjk \
  47. # install a package to improve the accuracy of guessing mime type and file extension
  48. media-types \
  49. # install libmagic to support the use of python-magic guess MIMETYPE
  50. libmagic1 \
  51. && apt-get autoremove -y \
  52. && rm -rf /var/lib/apt/lists/*
  53. # Copy Python environment and packages
  54. ENV VIRTUAL_ENV=/app/api/.venv
  55. COPY --from=packages ${VIRTUAL_ENV} ${VIRTUAL_ENV}
  56. ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
  57. # Download nltk data
  58. RUN python -c "import nltk; nltk.download('punkt'); nltk.download('averaged_perceptron_tagger')"
  59. ENV TIKTOKEN_CACHE_DIR=/app/api/.tiktoken_cache
  60. RUN python -c "import tiktoken; tiktoken.encoding_for_model('gpt2')"
  61. # Copy source code
  62. COPY . /app/api/
  63. # Copy entrypoint
  64. COPY docker/entrypoint.sh /entrypoint.sh
  65. RUN chmod +x /entrypoint.sh
  66. ARG COMMIT_SHA
  67. ENV COMMIT_SHA=${COMMIT_SHA}
  68. ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]