Spaces:
Sleeping
Sleeping
File size: 1,693 Bytes
7eee4f2 1d9bd0b 7eee4f2 1d9bd0b 7eee4f2 1d9bd0b 7eee4f2 1d9bd0b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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"] |