FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt && pip cache purge

# Install system dependencies
# ffmpeg: video/audio processing for media handling
# libgl1: OpenGL library required by opencv-contrib-python
# libglib2.0-0: GLib library (common dependency)
RUN apt-get update && apt-get install -y \
    ffmpeg \
    libgl1 \
    libglib2.0-0 \
    ca-certificates \
    curl \
    gnupg \
    lsb-release \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* \
 && rm -rf /usr/share/doc

# Install Playwright browsers with system dependencies (for UNO automation)
RUN playwright install --with-deps chromium

# Remove unused system packages to reduce image size
# Note: Playwright installs many dependencies; we remove what we can safely
RUN apt-get remove -y \
    pocketsphinx-en-us \
    pocketsphinx \
    libflite1 \
    libpocketsphinx3 \
    mesa-vulkan-drivers \
    mesa-va-drivers \
    mesa-vdpau-drivers \
    libvulkan1 \
 || true && \
apt-get autoremove -y && \
apt-get install -y libgl1 libglib2.0-0 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install Docker CLI and docker compose plugin so the bot can build/create the face detector container
RUN set -eux; \
    curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg; \
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
        > /etc/apt/sources.list.d/docker.list; \
    apt-get update; \
    apt-get install -y docker-ce-cli docker-compose-plugin; \
    apt-get clean; rm -rf /var/lib/apt/lists/*

COPY bot.py .
COPY server_manager.py .
COPY command_router.py .
COPY config.py .
COPY config_manager.py .
COPY utils /app/utils
COPY commands /app/commands
COPY memory /app/memory
COPY static /app/static
COPY globals.py .
COPY api.py .
COPY api_main.py .
COPY miku_lore.txt .
COPY miku_prompt.txt .
COPY miku_lyrics.txt .
COPY evil_miku_lore.txt .
COPY evil_miku_prompt.txt .
COPY evil_miku_lyrics.txt .
COPY MikuMikuBeam.mp4 .
COPY Miku_BasicWorkflow.json .
COPY moods /app/moods/

CMD ["python", "-u", "bot.py"]
