Dockerfile 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. ARG BUILD_HASH=dev-build
  15. # Override at your own risk - non-root configurations are untested
  16. ARG UID=0
  17. ARG GID=0
  18. ######## WebUI frontend ########
  19. FROM --platform=$BUILDPLATFORM node:21-alpine3.19 as build
  20. ARG BUILD_HASH
  21. WORKDIR /app
  22. COPY package.json package-lock.json ./
  23. RUN npm ci
  24. COPY . .
  25. ENV APP_BUILD_HASH=${BUILD_HASH}
  26. RUN npm run build
  27. ######## WebUI backend ########
  28. FROM python:3.11-slim-bookworm as base
  29. # Use args
  30. ARG USE_CUDA
  31. ARG USE_OLLAMA
  32. ARG USE_CUDA_VER
  33. ARG USE_EMBEDDING_MODEL
  34. ARG USE_RERANKING_MODEL
  35. ARG BUILD_HASH
  36. ARG UID
  37. ARG GID
  38. ## Basis ##
  39. ENV ENV=prod \
  40. PORT=8080 \
  41. # pass build args to the build
  42. USE_OLLAMA_DOCKER=${USE_OLLAMA} \
  43. USE_CUDA_DOCKER=${USE_CUDA} \
  44. USE_CUDA_DOCKER_VER=${USE_CUDA_VER} \
  45. USE_EMBEDDING_MODEL_DOCKER=${USE_EMBEDDING_MODEL} \
  46. USE_RERANKING_MODEL_DOCKER=${USE_RERANKING_MODEL}
  47. ## Basis URL Config ##
  48. ENV OLLAMA_BASE_URL="/ollama" \
  49. OPENAI_API_BASE_URL=""
  50. ## API Key and Security Config ##
  51. ENV OPENAI_API_KEY="" \
  52. WEBUI_SECRET_KEY="" \
  53. SCARF_NO_ANALYTICS=true \
  54. DO_NOT_TRACK=true \
  55. ANONYMIZED_TELEMETRY=false
  56. # Use locally bundled version of the LiteLLM cost map json
  57. # to avoid repetitive startup connections
  58. ENV LITELLM_LOCAL_MODEL_COST_MAP="True"
  59. #### Other models #########################################################
  60. ## whisper TTS model settings ##
  61. ENV WHISPER_MODEL="base" \
  62. WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
  63. ## RAG Embedding model settings ##
  64. ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \
  65. RAG_RERANKING_MODEL="$USE_RERANKING_MODEL_DOCKER" \
  66. SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
  67. ## Hugging Face download cache ##
  68. ENV HF_HOME="/app/backend/data/cache/embedding/models"
  69. #### Other models ##########################################################
  70. WORKDIR /app/backend
  71. ENV HOME /root
  72. # Create user and group if not root
  73. RUN if [ $UID -ne 0 ]; then \
  74. if [ $GID -ne 0 ]; then \
  75. addgroup --gid $GID app; \
  76. fi; \
  77. adduser --uid $UID --gid $GID --home $HOME --disabled-password --no-create-home app; \
  78. fi
  79. RUN mkdir -p $HOME/.cache/chroma
  80. RUN echo -n 00000000-0000-0000-0000-000000000000 > $HOME/.cache/chroma/telemetry_user_id
  81. # Make sure the user has access to the app and root directory
  82. RUN chown -R $UID:$GID /app $HOME
  83. RUN if [ "$USE_OLLAMA" = "true" ]; then \
  84. apt-get update && \
  85. # Install pandoc and netcat
  86. apt-get install -y --no-install-recommends pandoc netcat-openbsd curl && \
  87. # for RAG OCR
  88. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  89. # install helper tools
  90. apt-get install -y --no-install-recommends curl jq && \
  91. # install ollama
  92. curl -fsSL https://ollama.com/install.sh | sh && \
  93. # cleanup
  94. rm -rf /var/lib/apt/lists/*; \
  95. else \
  96. apt-get update && \
  97. # Install pandoc and netcat
  98. apt-get install -y --no-install-recommends pandoc netcat-openbsd curl jq && \
  99. # for RAG OCR
  100. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  101. # cleanup
  102. rm -rf /var/lib/apt/lists/*; \
  103. fi
  104. # install python dependencies
  105. COPY --chown=$UID:$GID ./backend/requirements.txt ./requirements.txt
  106. RUN pip3 install uv && \
  107. if [ "$USE_CUDA" = "true" ]; then \
  108. # If you use CUDA the whisper and embedding model will be downloaded on first use
  109. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
  110. uv pip install --system -r requirements.txt --no-cache-dir && \
  111. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  112. 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'])"; \
  113. else \
  114. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
  115. uv pip install --system -r requirements.txt --no-cache-dir && \
  116. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  117. 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'])"; \
  118. fi; \
  119. chown -R $UID:$GID /app/backend/data/
  120. # copy embedding weight from build
  121. # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
  122. # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
  123. # copy built frontend files
  124. COPY --chown=$UID:$GID --from=build /app/build /app/build
  125. COPY --chown=$UID:$GID --from=build /app/CHANGELOG.md /app/CHANGELOG.md
  126. COPY --chown=$UID:$GID --from=build /app/package.json /app/package.json
  127. # copy backend files
  128. COPY --chown=$UID:$GID ./backend .
  129. EXPOSE 8080
  130. HEALTHCHECK CMD curl --silent --fail http://localhost:8080/health | jq -e '.status == true' || exit 1
  131. USER $UID:$GID
  132. ENV WEBUI_BUILD_VERSION=${BUILD_HASH}
  133. CMD [ "bash", "start.sh"]