FROM python:3.11-slim

# Install system dependencies (ffmpeg is required for audio extraction/spotDL)
RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    curl \
    git \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Install Deno for yt-dlp JavaScript decryption support
COPY --from=denoland/deno:bin /deno /usr/local/bin/deno

# Set working directory
WORKDIR /app

# Install python dependencies directly (keeps container lightweight)
RUN pip install --no-cache-dir \
    fastapi \
    uvicorn \
    requests \
    beautifulsoup4 \
    mutagen \
    spotdl \
    yt-dlp \
    curl_cffi

# Copy application files
COPY main.py tasks.py /app/

# Initialize directories and set permissions for k8s volumes
RUN mkdir -p /tmp/downloads && chmod 777 /tmp/downloads
RUN mkdir -p /remote-music && chmod 777 /remote-music

# Expose FastAPI default port
EXPOSE 8000

# Start FastAPI application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
