# Use an official Python runtime as a parent image FROM python:3.10-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV PORT=7860 # Install system dependencies RUN apt-get update && apt-get install -y \ ffmpeg \ imagemagick \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender1 \ build-essential \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Fix ImageMagick policy to allow processing (checking both version 6 and 7) RUN if [ -f /etc/ImageMagick-6/policy.xml ]; then \ sed -i 's/domain="path" rights="none" pattern="@\*"/domain="path" rights="read|write" pattern="@\*"/g' /etc/ImageMagick-6/policy.xml; \ fi; \ if [ -f /etc/ImageMagick-7/policy.xml ]; then \ sed -i 's/domain="path" rights="none" pattern="@\*"/domain="path" rights="read|write" pattern="@\*"/g' /etc/ImageMagick-7/policy.xml; \ fi # Create a non-root user RUN useradd -m -u 1000 user # Set working directory and ownership WORKDIR /app RUN chown -R user:user /app # Switch to non-root user USER user ENV PATH="/home/user/.local/bin:$PATH" # Copy requirements and install COPY --chown=user:user ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt # Copy the rest of the application COPY --chown=user:user . /app # Create necessary directories with correct permissions RUN mkdir -p uploads outputs/viral_clips temp logs fonts && \ chmod -R 755 uploads outputs/viral_clips temp logs fonts # Expose the port EXPOSE 7860 # Run the application CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]