# Use Python 3.11 slim image as base FROM python:3.11-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ DEBIAN_FRONTEND=noninteractive \ PORT=7860 # Set work directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ curl \ wget \ ca-certificates \ gnupg \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Install latest yt-dlp binary and auto-update it RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp \ && chmod a+rx /usr/local/bin/yt-dlp \ && yt-dlp -vU # Copy requirements first for better caching COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir --upgrade pip \ && pip install --no-cache-dir -r requirements.txt # Copy the rest of your app COPY . . # Create a downloads directory with proper permissions RUN mkdir -p /tmp/downloads && chmod 755 /tmp/downloads # Create a non-root user and give access to app and temp directories RUN useradd --create-home --shell /bin/bash app \ && chown -R app:app /app \ && chown -R app:app /tmp/downloads # Switch to non-root user USER app # Expose app port EXPOSE ${PORT} # Healthcheck endpoint HEALTHCHECK --interval=60s --timeout=30s --start-period=10s --retries=3 \ CMD curl -f http://localhost:${PORT}/health || exit 1 # Start the app CMD ["python", "main.py"]