Spaces:
Sleeping
Sleeping
# Use Python 3.11.9 to match your runtime | |
FROM python:3.11.9 | |
# Set working directory | |
WORKDIR /code | |
# Install system dependencies | |
RUN apt-get update && apt-get install -y \ | |
ffmpeg \ | |
libsndfile1 \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Copy requirements and install Python dependencies | |
COPY ./requirements.txt /code/requirements.txt | |
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | |
# CREATE NON-ROOT USER - This is the key addition | |
RUN useradd -m -u 1000 user | |
# Create necessary directories with proper ownership | |
RUN mkdir -p /code/models /tmp/uploads /tmp/audiocraft_cache /home/user/.cache | |
RUN chown -R user:user /code /tmp/uploads /tmp/audiocraft_cache /home/user | |
# Switch to non-root user | |
USER user | |
# Set environment variables for the user | |
ENV HOME=/home/user \ | |
PATH=/home/user/.local/bin:$PATH | |
# Set working directory in user's space | |
WORKDIR /home/user/app | |
# Copy application code with proper ownership | |
COPY --chown=user:user . /home/user/app | |
# Expose port 7860 (required for HF Spaces) | |
EXPOSE 7860 | |
# Run the FastAPI application with Gradio mounted | |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] |