Dockerfile 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 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. #### Other models ##########################################################
  66. WORKDIR /app/backend
  67. ENV HOME /root
  68. # Create user and group if not root
  69. RUN if [ $UID -ne 0 ]; then \
  70. if [ $GID -ne 0 ]; then \
  71. addgroup --gid $GID app; \
  72. fi; \
  73. adduser --uid $UID --gid $GID --home $HOME --disabled-password --no-create-home app; \
  74. fi
  75. RUN mkdir -p $HOME/.cache/chroma
  76. RUN echo -n 00000000-0000-0000-0000-000000000000 > $HOME/.cache/chroma/telemetry_user_id
  77. # Make sure the user has access to the app and root directory
  78. RUN chown -R $UID:$GID /app $HOME
  79. RUN if [ "$USE_OLLAMA" = "true" ]; then \
  80. apt-get update && \
  81. # Install pandoc and netcat
  82. apt-get install -y --no-install-recommends pandoc netcat-openbsd curl && \
  83. # for RAG OCR
  84. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  85. # install helper tools
  86. apt-get install -y --no-install-recommends curl jq && \
  87. # install ollama
  88. curl -fsSL https://ollama.com/install.sh | sh && \
  89. # cleanup
  90. rm -rf /var/lib/apt/lists/*; \
  91. else \
  92. apt-get update && \
  93. # Install pandoc and netcat
  94. apt-get install -y --no-install-recommends pandoc netcat-openbsd curl jq && \
  95. # for RAG OCR
  96. apt-get install -y --no-install-recommends ffmpeg libsm6 libxext6 && \
  97. # cleanup
  98. rm -rf /var/lib/apt/lists/*; \
  99. fi
  100. # install python dependencies
  101. COPY --chown=$UID:$GID ./backend/requirements.txt ./requirements.txt
  102. RUN pip3 install uv && \
  103. if [ "$USE_CUDA" = "true" ]; then \
  104. # If you use CUDA the whisper and embedding model will be downloaded on first use
  105. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
  106. uv pip install --system -r requirements.txt --no-cache-dir && \
  107. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  108. 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'])"; \
  109. else \
  110. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
  111. uv pip install --system -r requirements.txt --no-cache-dir && \
  112. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  113. 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'])"; \
  114. fi; \
  115. chown -R $UID:$GID /app/backend/data/
  116. # copy embedding weight from build
  117. # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
  118. # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
  119. # copy built frontend files
  120. COPY --chown=$UID:$GID --from=build /app/build /app/build
  121. COPY --chown=$UID:$GID --from=build /app/CHANGELOG.md /app/CHANGELOG.md
  122. COPY --chown=$UID:$GID --from=build /app/package.json /app/package.json
  123. # copy backend files
  124. COPY --chown=$UID:$GID ./backend .
  125. EXPOSE 8080
  126. HEALTHCHECK CMD curl --silent --fail http://localhost:8080/health | jq -e '.status == true' || exit 1
  127. USER $UID:$GID
  128. ARG BUILD_HASH
  129. ENV WEBUI_BUILD_VERSION=${BUILD_HASH}
  130. CMD [ "bash", "start.sh"]