Dockerfile 7.0 KB

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