kybocr / Dockerfile
tommulder's picture
start-server permissions
65907ea
raw
history blame
2.69 kB
# Base: official vLLM OpenAI-compatible server (tested version family)
FROM vllm/vllm-openai:v0.9.1
# Install required packages as root
RUN pip3 install flash_attn==2.8.0.post2
RUN pip3 install transformers==4.51.3
# vLLM needs the custom model to be registered before main() runs.
# The model authors recommend importing their vLLM adapter into the vllm CLI module.
# Do this as root before switching to user (required for HF Spaces)
RUN sed -i '/^from vllm\.entrypoints\.cli\.main import main$/a\
from DotsOCR import modeling_dots_ocr_vllm' $(which vllm)
# Show the patched part of the vllm script for verification
RUN grep -A 1 'from vllm.entrypoints.cli.main import main' $(which vllm)
# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user
# Copy the startup script and make it executable (as root)
COPY start_server.sh /home/user/app/start_server.sh
RUN chmod +x /home/user/app/start_server.sh
# Switch to the "user" user
USER user
# Set home to the user's home directory and update PATH
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Set the working directory to the user's home directory
WORKDIR $HOME/app
# Speed up HF downloads and avoid interactive git prompts
ENV HF_HUB_ENABLE_HF_TRANSFER=1 \
GIT_LFS_SKIP_SMUDGE=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Pre-download the model repo using Hugging Face cache
# Note: dots.ocr requires the directory name to avoid '.' (see model card).
ARG MODEL_ID=rednote-hilab/dots.ocr
RUN python3 - <<'PY'
from huggingface_hub import snapshot_download
import os
# Download model to HF cache (default location: ~/.cache/huggingface/hub)
# This automatically handles caching, deduplication, and proper directory structure
model_path = snapshot_download(
repo_id=os.environ.get("MODEL_ID", "rednote-hilab/dots.ocr"),
allow_patterns=["*"]
)
print(f"Model downloaded to: {model_path}")
# Write the model path to a file for later use
with open("/home/user/app/model_path.txt", "w") as f:
f.write(model_path)
PY
# Set the model path from the downloaded location
RUN HF_MODEL_PATH=$(cat /home/user/app/model_path.txt) && \
echo "export HF_MODEL_PATH=$HF_MODEL_PATH" >> /home/user/.bashrc && \
echo "export PYTHONPATH=\"$HF_MODEL_PATH:\$PYTHONPATH\"" >> /home/user/.bashrc
# Set default environment variables (will be overridden by .bashrc in interactive shells)
ENV HF_MODEL_PATH=/home/user/.cache/huggingface/hub/models--rednote-hilab--dots.ocr
ENV PYTHONPATH="/home/user/.cache/huggingface/hub/models--rednote-hilab--dots.ocr:${PYTHONPATH}"
# Expose the Space port
EXPOSE 7860
ENV PORT=7860
# Use the startup script as entrypoint
ENTRYPOINT ["/home/user/app/start_server.sh"]