Dockerfile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # syntax=docker/dockerfile:1
  2. # Initialize device type args
  3. # use build args in the docker build commmand with --build-arg="BUILDARG=true"
  4. ARG USE_CUDA=false
  5. ARG USE_OLLAMA=false
  6. # Tested with cu117 for CUDA 11 and cu121 for CUDA 12 (default)
  7. ARG USE_CUDA_VER=cu121
  8. # any sentence transformer model; models to use can be found at https://huggingface.co/models?library=sentence-transformers
  9. # Leaderboard: https://huggingface.co/spaces/mteb/leaderboard
  10. # for better performance and multilangauge support use "intfloat/multilingual-e5-large" (~2.5GB) or "intfloat/multilingual-e5-base" (~1.5GB)
  11. # IMPORTANT: If you change the embedding model (sentence-transformers/all-MiniLM-L6-v2) and vice versa, you aren't able to use RAG Chat with your previous documents loaded in the WebUI! You need to re-embed them.
  12. ARG USE_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
  13. ARG USE_RERANKING_MODEL=""
  14. # Override at your own risk - non-root configurations are untested
  15. ARG UID=0
  16. ARG GID=0
  17. ######## WebUI frontend ########
  18. FROM --platform=$BUILDPLATFORM node:21-alpine3.19 as build
  19. WORKDIR /app
  20. COPY package.json package-lock.json ./
  21. RUN npm ci
  22. COPY . .
  23. RUN npm run build
  24. ######## WebUI backend ########
  25. FROM python:3.11-slim-bookworm as base
  26. # Use args
  27. ARG USE_CUDA
  28. ARG USE_OLLAMA
  29. ARG USE_CUDA_VER
  30. ARG USE_EMBEDDING_MODEL
  31. ARG USE_RERANKING_MODEL
  32. ARG UID
  33. ARG GID
  34. ## Basis ##
  35. ENV ENV=prod \
  36. PORT=8080 \
  37. # pass build args to the build
  38. USE_OLLAMA_DOCKER=${USE_OLLAMA} \
  39. USE_CUDA_DOCKER=${USE_CUDA} \
  40. USE_CUDA_DOCKER_VER=${USE_CUDA_VER} \
  41. USE_EMBEDDING_MODEL_DOCKER=${USE_EMBEDDING_MODEL} \
  42. USE_RERANKING_MODEL_DOCKER=${USE_RERANKING_MODEL}
  43. ## Basis URL Config ##
  44. ENV OLLAMA_BASE_URL="/ollama" \
  45. OPENAI_API_BASE_URL=""
  46. ## API Key and Security Config ##
  47. ENV OPENAI_API_KEY="" \
  48. WEBUI_SECRET_KEY="" \
  49. SCARF_NO_ANALYTICS=true \
  50. DO_NOT_TRACK=true \
  51. ANONYMIZED_TELEMETRY=false
  52. #### Other models #########################################################
  53. ## whisper TTS model settings ##
  54. ENV WHISPER_MODEL="base" \
  55. WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
  56. ## RAG Embedding model settings ##
  57. ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \
  58. RAG_RERANKING_MODEL="$USE_RERANKING_MODEL_DOCKER" \
  59. SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
  60. ## Hugging Face download cache ##
  61. ENV HF_HOME="/app/backend/data/cache/embedding/models"
  62. #### Other models ##########################################################
  63. WORKDIR /app/backend
  64. ENV HOME /root
  65. # Create user and group if not root
  66. RUN if [ $UID -ne 0 ]; then \
  67. if [ $GID -ne 0 ]; then \
  68. addgroup --gid $GID app; \
  69. fi; \
  70. adduser --uid $UID --gid $GID --home $HOME --disabled-password --no-create-home app; \
  71. fi
  72. RUN mkdir -p $HOME/.cache/chroma
  73. RUN echo -n 00000000-0000-0000-0000-000000000000 > $HOME/.cache/chroma/telemetry_user_id
  74. # Make sure the user has access to the app and root directory
  75. RUN chown -R $UID:$GID /app $HOME
  76. RUN if [ "$USE_OLLAMA" = "true" ]; then \
  77. apt-get update && \
  78. # Install pandoc and netcat
  79. apt-get install -y --no-install-recommends pandoc netcat-openbsd curl && \
  80. # for RAG OCR
  81. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  82. # install helper tools
  83. apt-get install -y --no-install-recommends curl jq && \
  84. # install ollama
  85. curl -fsSL https://ollama.com/install.sh | sh && \
  86. # cleanup
  87. rm -rf /var/lib/apt/lists/*; \
  88. else \
  89. apt-get update && \
  90. # Install pandoc and netcat
  91. apt-get install -y --no-install-recommends pandoc netcat-openbsd curl jq && \
  92. # for RAG OCR
  93. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  94. # cleanup
  95. rm -rf /var/lib/apt/lists/*; \
  96. fi
  97. # install python dependencies
  98. COPY --chown=$UID:$GID ./backend/requirements.txt ./requirements.txt
  99. RUN pip3 install uv && \
  100. if [ "$USE_CUDA" = "true" ]; then \
  101. # If you use CUDA the whisper and embedding model will be downloaded on first use
  102. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
  103. uv pip install --system -r requirements.txt --no-cache-dir && \
  104. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  105. python -c "import os; from faster_whisper import WhisperModel; WhisperModel(os.environ['WHISPER_MODEL'], device='cpu', compute_type='int8', download_root=os.environ['WHISPER_MODEL_DIR'])"; \
  106. else \
  107. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
  108. uv pip install --system -r requirements.txt --no-cache-dir && \
  109. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  110. python -c "import os; from faster_whisper import WhisperModel; WhisperModel(os.environ['WHISPER_MODEL'], device='cpu', compute_type='int8', download_root=os.environ['WHISPER_MODEL_DIR'])"; \
  111. fi; \
  112. chown -R $UID:$GID /app/backend/data/
  113. # copy embedding weight from build
  114. # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
  115. # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
  116. # copy built frontend files
  117. COPY --chown=$UID:$GID --from=build /app/build /app/build
  118. COPY --chown=$UID:$GID --from=build /app/CHANGELOG.md /app/CHANGELOG.md
  119. COPY --chown=$UID:$GID --from=build /app/package.json /app/package.json
  120. # copy backend files
  121. COPY --chown=$UID:$GID ./backend .
  122. EXPOSE 8080
  123. HEALTHCHECK CMD curl --silent --fail http://localhost:8080/health | jq -e '.status == true' || exit 1
  124. USER $UID:$GID
  125. CMD [ "bash", "start.sh"]