Dockerfile 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # syntax=docker/dockerfile:1
  2. # Initialize device type args
  3. # use build args in the docker build command with --build-arg="BUILDARG=true"
  4. ARG USE_CUDA=false
  5. ARG USE_OLLAMA=false
  6. ARG USE_SLIM=false
  7. # Tested with cu117 for CUDA 11 and cu121 for CUDA 12 (default)
  8. ARG USE_CUDA_VER=cu128
  9. # any sentence transformer model; models to use can be found at https://huggingface.co/models?library=sentence-transformers
  10. # Leaderboard: https://huggingface.co/spaces/mteb/leaderboard
  11. # for better performance and multilangauge support use "intfloat/multilingual-e5-large" (~2.5GB) or "intfloat/multilingual-e5-base" (~1.5GB)
  12. # 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.
  13. ARG USE_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
  14. ARG USE_RERANKING_MODEL=""
  15. # Tiktoken encoding name; models to use can be found at https://huggingface.co/models?library=tiktoken
  16. ARG USE_TIKTOKEN_ENCODING_NAME="cl100k_base"
  17. ARG BUILD_HASH=dev-build
  18. # Override at your own risk - non-root configurations are untested
  19. ARG UID=0
  20. ARG GID=0
  21. ######## WebUI frontend ########
  22. FROM --platform=$BUILDPLATFORM node:22-alpine3.20 AS build
  23. ARG BUILD_HASH
  24. WORKDIR /app
  25. # to store git revision in build
  26. RUN apk add --no-cache git
  27. COPY package.json package-lock.json ./
  28. RUN npm ci --force
  29. COPY . .
  30. ENV APP_BUILD_HASH=${BUILD_HASH}
  31. RUN npm run build
  32. ######## WebUI backend ########
  33. FROM python:3.11-slim-bookworm AS base
  34. # Use args
  35. ARG USE_CUDA
  36. ARG USE_OLLAMA
  37. ARG USE_CUDA_VER
  38. ARG USE_SLIM
  39. ARG USE_EMBEDDING_MODEL
  40. ARG USE_RERANKING_MODEL
  41. ARG UID
  42. ARG GID
  43. ## Basis ##
  44. ENV ENV=prod \
  45. PORT=8080 \
  46. # pass build args to the build
  47. USE_OLLAMA_DOCKER=${USE_OLLAMA} \
  48. USE_CUDA_DOCKER=${USE_CUDA} \
  49. USE_SLIM_DOCKER=${USE_SLIM} \
  50. USE_CUDA_DOCKER_VER=${USE_CUDA_VER} \
  51. USE_EMBEDDING_MODEL_DOCKER=${USE_EMBEDDING_MODEL} \
  52. USE_RERANKING_MODEL_DOCKER=${USE_RERANKING_MODEL}
  53. ## Basis URL Config ##
  54. ENV OLLAMA_BASE_URL="/ollama" \
  55. OPENAI_API_BASE_URL=""
  56. ## API Key and Security Config ##
  57. ENV OPENAI_API_KEY="" \
  58. WEBUI_SECRET_KEY="" \
  59. SCARF_NO_ANALYTICS=true \
  60. DO_NOT_TRACK=true \
  61. ANONYMIZED_TELEMETRY=false
  62. #### Other models #########################################################
  63. ## whisper TTS model settings ##
  64. ENV WHISPER_MODEL="base" \
  65. WHISPER_MODEL_DIR="/app/backend/data/cache/whisper/models"
  66. ## RAG Embedding model settings ##
  67. ENV RAG_EMBEDDING_MODEL="$USE_EMBEDDING_MODEL_DOCKER" \
  68. RAG_RERANKING_MODEL="$USE_RERANKING_MODEL_DOCKER" \
  69. SENTENCE_TRANSFORMERS_HOME="/app/backend/data/cache/embedding/models"
  70. ## Tiktoken model settings ##
  71. ENV TIKTOKEN_ENCODING_NAME="cl100k_base" \
  72. TIKTOKEN_CACHE_DIR="/app/backend/data/cache/tiktoken"
  73. ## Hugging Face download cache ##
  74. ENV HF_HOME="/app/backend/data/cache/embedding/models"
  75. ## Torch Extensions ##
  76. # ENV TORCH_EXTENSIONS_DIR="/.cache/torch_extensions"
  77. #### Other models ##########################################################
  78. WORKDIR /app/backend
  79. ENV HOME=/root
  80. # Create user and group if not root
  81. RUN if [ $UID -ne 0 ]; then \
  82. if [ $GID -ne 0 ]; then \
  83. addgroup --gid $GID app; \
  84. fi; \
  85. adduser --uid $UID --gid $GID --home $HOME --disabled-password --no-create-home app; \
  86. fi
  87. RUN mkdir -p $HOME/.cache/chroma
  88. RUN echo -n 00000000-0000-0000-0000-000000000000 > $HOME/.cache/chroma/telemetry_user_id
  89. # Make sure the user has access to the app and root directory
  90. RUN chown -R $UID:$GID /app $HOME
  91. # Install common system dependencies
  92. RUN apt-get update && \
  93. apt-get install -y --no-install-recommends \
  94. git build-essential pandoc gcc netcat-openbsd curl jq \
  95. python3-dev \
  96. ffmpeg libsm6 libxext6 \
  97. && rm -rf /var/lib/apt/lists/*
  98. # install python dependencies
  99. COPY --chown=$UID:$GID ./backend/requirements.txt ./requirements.txt
  100. RUN pip3 install --no-cache-dir uv && \
  101. if [ "$USE_SLIM" != "true" ]; then \
  102. if [ "$USE_CUDA" = "true" ]; then \
  103. # If you use CUDA the whisper and embedding model will be downloaded on first use
  104. pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
  105. uv pip install --system -r requirements.txt --no-cache-dir && \
  106. python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
  107. 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'])"; \
  108. python -c "import os; import tiktoken; tiktoken.get_encoding(os.environ['TIKTOKEN_ENCODING_NAME'])"; \
  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. python -c "import os; import tiktoken; tiktoken.get_encoding(os.environ['TIKTOKEN_ENCODING_NAME'])"; \
  115. fi; \
  116. else \
  117. uv pip install --system -r requirements.txt --no-cache-dir; \
  118. fi; \
  119. mkdir -p /app/backend/data && chown -R $UID:$GID /app/backend/data/
  120. # Install Ollama if requested
  121. RUN if [ "$USE_OLLAMA" = "true" ] && [ "$USE_SLIM" != "true" ]; then \
  122. date +%s > /tmp/ollama_build_hash && \
  123. echo "Cache broken at timestamp: `cat /tmp/ollama_build_hash`" && \
  124. curl -fsSL https://ollama.com/install.sh | sh && \
  125. rm -rf /var/lib/apt/lists/*; \
  126. fi
  127. # copy embedding weight from build
  128. # RUN mkdir -p /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2
  129. # COPY --from=build /app/onnx /root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
  130. # copy built frontend files
  131. COPY --chown=$UID:$GID --from=build /app/build /app/build
  132. COPY --chown=$UID:$GID --from=build /app/CHANGELOG.md /app/CHANGELOG.md
  133. COPY --chown=$UID:$GID --from=build /app/package.json /app/package.json
  134. # copy backend files
  135. COPY --chown=$UID:$GID ./backend .
  136. EXPOSE 8080
  137. HEALTHCHECK CMD curl --silent --fail http://localhost:${PORT:-8080}/health | jq -ne 'input.status == true' || exit 1
  138. # Minimal, atomic permission hardening for OpenShift (arbitrary UID):
  139. # - Group 0 owns /app and /root
  140. # - Directories are group-writable and have SGID so new files inherit GID 0
  141. RUN set -eux; \
  142. chgrp -R 0 /app /root || true; \
  143. chmod -R g+rwX /app /root || true; \
  144. find /app -type d -exec chmod g+s {} + || true; \
  145. find /root -type d -exec chmod g+s {} + || true
  146. USER $UID:$GID
  147. ARG BUILD_HASH
  148. ENV WEBUI_BUILD_VERSION=${BUILD_HASH}
  149. ENV DOCKER=true
  150. CMD [ "bash", "start.sh"]