Dockerfile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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:22-alpine3.20 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 UID
  36. ARG GID
  37. ## Basis ##
  38. ENV ENV=prod \
  39. PORT=8080 \
  40. # pass build args to the build
  41. USE_OLLAMA_DOCKER=${USE_OLLAMA} \
  42. USE_CUDA_DOCKER=${USE_CUDA} \
  43. USE_CUDA_DOCKER_VER=${USE_CUDA_VER} \
  44. USE_EMBEDDING_MODEL_DOCKER=${USE_EMBEDDING_MODEL} \
  45. USE_RERANKING_MODEL_DOCKER=${USE_RERANKING_MODEL}
  46. ## Basis URL Config ##
  47. ENV OLLAMA_BASE_URL="/ollama" \
  48. OPENAI_API_BASE_URL=""
  49. ## API Key and Security Config ##
  50. ENV OPENAI_API_KEY="" \
  51. WEBUI_SECRET_KEY="" \
  52. SCARF_NO_ANALYTICS=true \
  53. DO_NOT_TRACK=true \
  54. ANONYMIZED_TELEMETRY=false
  55. #### Other models #########################################################
  56. ## whisper TTS model settings ##
  57. ENV WHISPER_MODEL="base" \
  58. WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
  59. ## RAG Embedding model settings ##
  60. ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \
  61. RAG_RERANKING_MODEL="$USE_RERANKING_MODEL_DOCKER" \
  62. SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
  63. ## Hugging Face download cache ##
  64. ENV HF_HOME="/app/backend/data/cache/embedding/models"
  65. ## Torch Extensions ##
  66. # ENV TORCH_EXTENSIONS_DIR="/.cache/torch_extensions"
  67. #### Other models ##########################################################
  68. WORKDIR /app/backend
  69. ENV HOME=/root
  70. # Create user and group if not root
  71. RUN if [ $UID -ne 0 ]; then \
  72. if [ $GID -ne 0 ]; then \
  73. addgroup --gid $GID app; \
  74. fi; \
  75. adduser --uid $UID --gid $GID --home $HOME --disabled-password --no-create-home app; \
  76. fi
  77. RUN mkdir -p $HOME/.cache/chroma
  78. RUN echo -n 00000000-0000-0000-0000-000000000000 > $HOME/.cache/chroma/telemetry_user_id
  79. # Make sure the user has access to the app and root directory
  80. RUN chown -R $UID:$GID /app $HOME
  81. RUN if [ "$USE_OLLAMA" = "true" ]; then \
  82. apt-get update && \
  83. # Install pandoc and netcat
  84. apt-get install -y --no-install-recommends git build-essential pandoc netcat-openbsd curl && \
  85. apt-get install -y --no-install-recommends gcc python3-dev && \
  86. # for RAG OCR
  87. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  88. # install helper tools
  89. apt-get install -y --no-install-recommends curl jq && \
  90. # install ollama
  91. curl -fsSL https://ollama.com/install.sh | sh && \
  92. # cleanup
  93. rm -rf /var/lib/apt/lists/*; \
  94. else \
  95. apt-get update && \
  96. # Install pandoc, netcat and gcc
  97. apt-get install -y --no-install-recommends git build-essential pandoc gcc netcat-openbsd curl jq && \
  98. apt-get install -y --no-install-recommends gcc python3-dev && \
  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:${PORT:-8080}/health | jq -ne 'input.status == true' || exit 1
  131. USER $UID:$GID
  132. ARG BUILD_HASH
  133. ENV WEBUI_BUILD_VERSION=${BUILD_HASH}
  134. ENV DOCKER=true
  135. CMD [ "bash", "start.sh"]