FROM ubuntu:22.04 # Prevent interactive prompts during installation ENV DEBIAN_FRONTEND=noninteractive # Set environment variables for MoviePy ENV IMAGEMAGICK_BINARY=/usr/bin/convert ENV IMAGEIO_FFMPEG_EXE=/usr/bin/ffmpeg # Install system dependencies RUN apt-get update && apt-get install -y \ software-properties-common && \ add-apt-repository -y ppa:ubuntu-toolchain-r/test && \ apt-get update && apt-get install -y \ python3.9 \ python3-pip \ ffmpeg \ imagemagick \ && rm -rf /var/lib/apt/lists/* # Create a non-root user RUN useradd -m appuser # Set working directory WORKDIR /app # Copy application code COPY . . # Install Python dependencies globally RUN pip3 install -r requirements.txt # Set ownership and permissions RUN chown -R appuser:appuser /app && \ chown -R appuser:appuser /tmp && \ chmod -R 755 /app && \ chmod -R 777 /tmp # Create required directories and set permissions # Create required directories and set permissions RUN mkdir -p /app/resources/audio && \ mkdir -p /app/resources/fonts && \ mkdir -p /app/resources/intro && \ mkdir -p /app/resources/temp_video && \ chown -R appuser:appuser /app && \ chmod -R 755 /app && \ chmod -R 777 /app/resources/temp_video # Configure ImageMagick with a permissive policy RUN mv /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.bak || true RUN echo '\ \ \ \ \ \ \ \ \ ' > /etc/ImageMagick-6/policy.xml # Switch to non-root user USER appuser EXPOSE 7860 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]