Spaces:
Sleeping
Sleeping
| # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker | |
| # you will also find guides on how best to write your Dockerfile | |
| FROM python:3.11 | |
| # Set DEBIAN_FRONTEND to noninteractive to avoid prompts during apt-get install | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # --- System Package Installation (as root) --- | |
| # Copy the packages list first | |
| COPY ./packages.txt /app/packages.txt | |
| # Update apt lists, install packages from packages.txt, and clean up in one layer | |
| # Ensure packages.txt exists and has content, otherwise apt-get might fail. | |
| # Handle potential errors if packages.txt is empty or doesn't exist. | |
| RUN apt-get update && \ | |
| # Check if packages.txt exists and is not empty before trying to install | |
| if [ -s /app/packages.txt ]; then \ | |
| apt-get install -y --no-install-recommends $(cat /app/packages.txt | grep -v '^#' | grep -v '^\s*$'); \ | |
| else \ | |
| echo "packages.txt not found or is empty, skipping system package installation."; \ | |
| fi && \ | |
| apt-get clean && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # --- User Setup --- | |
| # Create a non-root user and switch to it | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| WORKDIR /app | |
| # --- Python Package Installation (as user) --- | |
| # Copy only requirements.txt first to leverage Docker cache | |
| COPY --chown=user ./requirements.txt requirements.txt | |
| RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
| # --- Application Code --- | |
| # Copy the rest of the application code | |
| COPY --chown=user . /app | |
| # --- Run Command --- | |
| # Expose the port the app runs on (optional but good practice) | |
| EXPOSE 7860 | |
| # Start the application | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |