Spaces:
Runtime error
Runtime error
FROM python:3.10-slim | |
WORKDIR /app | |
# Install required system dependencies | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends git gcc python3-dev && \ | |
rm -rf /var/lib/apt/lists/* | |
# Create a dedicated user and cache directory with proper permissions | |
RUN useradd -m appuser && \ | |
mkdir -p /cache && \ | |
chown appuser:appuser /cache | |
# Create and activate virtual environment | |
RUN python -m venv /opt/venv | |
ENV PATH="/opt/venv/bin:$PATH" | |
# Install Python dependencies | |
COPY requirements.txt . | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy application code (as non-root user) | |
COPY --chown=appuser:appuser . . | |
# Set environment variables | |
ENV TRANSFORMERS_CACHE=/cache | |
ENV PYTHONUNBUFFERED=1 | |
ENV PYTHONPATH=/app | |
# Switch to non-root user | |
USER appuser | |
# Create the cache directory with correct permissions | |
RUN mkdir -p /cache | |
EXPOSE 7860 | |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |