# Dockerfile for uni-api deployment on Hugging Face Spaces # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker # you will also find guides on how best to write your Dockerfile # 1. Base Image FROM python:3.9 # 2. Create a non-root user for security RUN useradd -m -u 1000 user USER user # Add user's local bin to PATH (for packages installed with pip install --user) ENV PATH="/home/user/.local/bin:$PATH" # 3. Set the working directory WORKDIR /app # 4. Clone the application code from GitHub, including submodules # IMPORTANT: Replace 'main' with the correct branch name if it's different! # Use --recurse-submodules to fetch the 'core' submodule content RUN git clone --branch main --recurse-submodules https://github.com/yym68686/uni-api.git . # 5. Install Python dependencies # Assumes requirements.txt is present in the cloned repository root RUN pip install --no-cache-dir --upgrade -r requirements.txt # 6. Copy necessary files from the build context (local or HF repo root) # Copy the API template and the entrypoint script into the image COPY --chown=user ./api.template.yaml /app/api.template.yaml COPY --chown=user ./entrypoint.sh /app/entrypoint.sh # 7. Make the entrypoint script executable RUN chmod +x /app/entrypoint.sh # 8. Set the entrypoint script to run on container start # This script will generate the final api.yaml using secrets/environment variables ENTRYPOINT ["/app/entrypoint.sh"] # 9. Define the default command to run the application # This command will be executed by the entrypoint script (passed as "$@") CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]