# Dockerfile simplificado y robusto para Hugging Face Spaces FROM python:3.10-slim # Variables de entorno ENV DEBIAN_FRONTEND=noninteractive ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 # Directorio de trabajo WORKDIR /app # Instalar dependencias del sistema críticas RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ gcc \ g++ \ make \ pkg-config \ python3-dev \ libffi-dev \ libssl-dev \ libcurl4-openssl-dev \ ca-certificates \ ffmpeg \ git \ git-lfs \ curl \ wget \ cargo \ rustc \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Instalar Rust para curl-cffi RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" # Actualizar pip RUN pip install --no-cache-dir --upgrade pip setuptools wheel # Instalar dependencias críticas en orden RUN pip install --no-cache-dir certifi requests brotli websockets # Instalar curl-cffi específicamente RUN pip install --no-cache-dir curl-cffi # Instalar yt-dlp con curl-cffi RUN pip install --no-cache-dir "yt-dlp[default,curl-cffi]" # Crear usuario RUN useradd -m -u 1000 user # Configurar directorios RUN mkdir -p /app/.cache /app/.config RUN chown -R user:user /app # Variables de entorno para el usuario ENV HF_HOME="/app/.cache" ENV MPLCONFIGDIR="/app/.cache" # Cambiar a usuario USER user # Copiar requirements y instalar resto de dependencias COPY --chown=user:user requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt # Configurar yt-dlp RUN mkdir -p ~/.config/yt-dlp RUN echo "--user-agent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'" > ~/.config/yt-dlp/config RUN echo "--sleep-interval 3" >> ~/.config/yt-dlp/config RUN echo "--geo-bypass" >> ~/.config/yt-dlp/config # Copiar aplicación COPY --chown=user:user app.py . # Script de inicio simple RUN echo '#!/bin/bash\necho "🚀 Starting App..."\necho "yt-dlp: $(yt-dlp --version)"\npython app.py' > start.sh && chmod +x start.sh # Puerto EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=20s --retries=3 \ CMD curl -f http://localhost:7860/ || exit 1 # Ejecutar CMD ["./start.sh"]