mirror of
https://github.com/onyx-dot-app/onyx.git
synced 2026-10-22 03:14:06 -05:00
86 lines
3.7 KiB
Docker
86 lines
3.7 KiB
Docker
# Registry prefix for base images. Defaults to Docker Hub; CI overrides this to the ECR
|
|
# pull-through cache (<account>.dkr.ecr.us-east-2.amazonaws.com/docker-hub) to avoid Docker
|
|
# Hub rate limits.
|
|
ARG BASE_IMAGE_REGISTRY=docker.io
|
|
|
|
# Base stage with dependencies
|
|
FROM ${BASE_IMAGE_REGISTRY}/library/python:3.13-slim@sha256:b04b5d7233d2ad9c379e22ea8927cd1378cd15c60d4ef876c065b25ea8fb3bf3 AS base
|
|
|
|
ENV ONYX_RUNNING_IN_DOCKER="true" \
|
|
HF_HOME=/app/.cache/huggingface
|
|
|
|
COPY --from=ghcr.io/astral-sh/uv:0.11.25@sha256:1e3808aa9023d0980e7c15b1fa7c1ac16ff35925780cf5c459858b2d693f01a9 /uv /uvx /bin/
|
|
|
|
RUN mkdir -p /app/.cache/huggingface
|
|
|
|
COPY ./requirements/model_server.txt /tmp/requirements.txt
|
|
|
|
# Install torch + CUDA/GPU deps in a dedicated layer: together they are ~3GB,
|
|
# and isolating them avoids a single oversized layer that is unreliable to push.
|
|
# awk extracts each matching package block in full — the package line plus its
|
|
# `--hash=...` continuation lines — so --require-hashes can verify them.
|
|
RUN awk '/^[[:alnum:]]/ { keep = ($0 ~ /^(torch|nvidia-[a-z0-9-]+|triton)==/) } keep' /tmp/requirements.txt \
|
|
| uv pip install --system --no-cache-dir --no-deps --require-hashes -r /dev/stdin && \
|
|
rm -rf ~/.cache/uv
|
|
|
|
# TODO: drop --no-deps once we upgrade to a litellm version with looser dependencies.
|
|
RUN uv pip install --system --no-cache-dir --no-deps --require-hashes \
|
|
-r /tmp/requirements.txt && \
|
|
rm -rf ~/.cache/uv /tmp/*.txt
|
|
|
|
# Stage for downloading embedding models. Instantiating SentenceTransformer
|
|
# pulls down both the weights and the custom architecture code.
|
|
FROM base AS embedding-models
|
|
RUN python -c "from sentence_transformers import SentenceTransformer; \
|
|
SentenceTransformer(model_name_or_path='nomic-ai/nomic-embed-text-v1', trust_remote_code=True);"
|
|
|
|
# Final stage - combine all downloads
|
|
FROM base AS final
|
|
|
|
LABEL com.danswer.maintainer="founders@onyx.app"
|
|
LABEL com.danswer.description="This image is for the Onyx model server which runs all of the \
|
|
AI models for Onyx. This container and all the code is MIT Licensed and free for all to use. \
|
|
You can find it at https://hub.docker.com/r/onyx/onyx-model-server. For more details, \
|
|
visit https://github.com/onyx-dot-app/onyx."
|
|
|
|
# Create non-root user for security best practices
|
|
RUN groupadd -g 1001 onyx && \
|
|
useradd -u 1001 -g onyx -m -s /bin/bash onyx && \
|
|
mkdir -p /var/log/onyx && \
|
|
chmod 755 /var/log/onyx && \
|
|
chown onyx:onyx /var/log/onyx
|
|
|
|
# In case the user has volumes mounted to /app/.cache/huggingface that they've downloaded while
|
|
# running Onyx, move the current contents of the cache folder to a temporary location to ensure
|
|
# it's preserved in order to combine with the user's cache contents
|
|
COPY --chown=onyx:onyx --from=embedding-models /app/.cache/huggingface /app/.cache/temp_huggingface
|
|
|
|
WORKDIR /app
|
|
|
|
# Utils used by model server
|
|
COPY ./onyx/utils/logger.py /app/onyx/utils/logger.py
|
|
COPY ./onyx/utils/platform_utils.py /app/onyx/utils/platform_utils.py
|
|
COPY ./onyx/utils/middleware.py /app/onyx/utils/middleware.py
|
|
COPY ./onyx/utils/tenant.py /app/onyx/utils/tenant.py
|
|
|
|
# Sentry configuration (used when SENTRY_DSN is set)
|
|
COPY ./onyx/configs/__init__.py /app/onyx/configs/__init__.py
|
|
COPY ./onyx/configs/sentry.py /app/onyx/configs/sentry.py
|
|
|
|
# Place to fetch version information
|
|
COPY ./onyx/__init__.py /app/onyx/__init__.py
|
|
|
|
# Shared between Onyx Backend and Model Server
|
|
COPY ./shared_configs /app/shared_configs
|
|
|
|
# Model Server main code
|
|
COPY ./model_server /app/model_server
|
|
|
|
ENV PYTHONPATH=/app
|
|
|
|
# Default ONYX_VERSION, typically overriden during builds by GitHub Actions.
|
|
ARG ONYX_VERSION=0.0.0-dev
|
|
ENV ONYX_VERSION=${ONYX_VERSION}
|
|
|
|
CMD ["uvicorn", "model_server.main:app", "--host", "0.0.0.0", "--port", "9000"]
|