feat(dockerfile): pre-download tiktoken in offline non_root image

This commit is contained in:
Hexoplon 2025-01-06 20:50:32 +01:00
parent 23685e93f3
commit a82d45e6ad
No known key found for this signature in database

View file

@ -35,6 +35,10 @@ RUN pip install dist/*.whl
# install dependencies as wheels # install dependencies as wheels
RUN pip wheel --no-cache-dir --wheel-dir=/wheels/ -r requirements.txt RUN pip wheel --no-cache-dir --wheel-dir=/wheels/ -r requirements.txt
# Download tiktoken for offline usage of image, see https://stackoverflow.com/a/76107077. Let tiktoken itself download the file, to ensure correct naming
ENV TIKTOKEN_CACHE_DIR="/tiktoken"
RUN mkdir /tiktoken && python -c "import tiktoken; tiktoken.get_encoding('cl100k_base'); print('tiktoken imported successfully')"
# Runtime stage # Runtime stage
FROM $LITELLM_RUNTIME_IMAGE AS runtime FROM $LITELLM_RUNTIME_IMAGE AS runtime
@ -50,6 +54,10 @@ RUN ls -la /app
COPY --from=builder /app/dist/*.whl . COPY --from=builder /app/dist/*.whl .
COPY --from=builder /wheels/ /wheels/ COPY --from=builder /wheels/ /wheels/
# Copy tiktoken from build stage, and set env variable to stop tiktoken from downloading file
COPY --from=builder /tiktoken /tiktoken
ENV CUSTOM_TIKTOKEN_CACHE_DIR="/tiktoken"
# Install the built wheel using pip; again using a wildcard if it's the only file # Install the built wheel using pip; again using a wildcard if it's the only file
RUN pip install *.whl /wheels/* --no-index --find-links=/wheels/ && rm -f *.whl && rm -rf /wheels RUN pip install *.whl /wheels/* --no-index --find-links=/wheels/ && rm -f *.whl && rm -rf /wheels