FROM debian:bookworm

# Install base system dependencies
RUN apt-get update && \
    apt-get install -y wget curl gnupg ca-certificates bash unzip build-essential \
        fonts-liberation libglib2.0-0 libnspr4 libnss3 libx11-6 libxkbcommon0 \
        libatk1.0-0 libgbm1 libasound2 libpangocairo-1.0-0 ffmpeg zlib1g-dev \
        libssl-dev libbz2-dev libreadline-dev libsqlite3-dev libffi-dev && \
    \
    # Install Node.js 18.x (LTS)
    curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
    apt-get install -y nodejs && \
    \
    # 🧩 Install Google Chrome (with proper keyring)
    mkdir -p /usr/share/keyrings && \
    curl -fsSL https://dl.google.com/linux/linux_signing_key.pub \
        | gpg --dearmor -o /usr/share/keyrings/google-linux-signing-keyring.gpg && \
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/google-linux-signing-keyring.gpg] \
        http://dl.google.com/linux/chrome/deb/ stable main" \
        > /etc/apt/sources.list.d/google-chrome.list && \
    apt-get update && \
    apt-get install -y google-chrome-stable && \
    \
    # --- Build & install Python 3.12 from source ---
    cd /tmp && \
    wget https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tgz && \
    tar -xzf Python-3.12.7.tgz && \
    cd Python-3.12.7 && \
    ./configure --enable-optimizations && \
    make -j"$(nproc)" && make altinstall && \
    ln -sf /usr/local/bin/python3.12 /usr/bin/python3 && \
    \
    # Install pip & Python packages
    curl -sS https://bootstrap.pypa.io/get-pip.py | python3 && \
    pip3 install --no-cache-dir requests beautifulsoup4 lxml && \
    \
    # Clean up build files
    cd / && rm -rf /tmp/Python-3.12.7* && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# --- Install StashApp ---
WORKDIR /opt
RUN wget https://github.com/stashapp/stash/releases/latest/download/stash-linux -O stash && \
    chmod +x stash && \
    ln -s /opt/stash /usr/local/bin/stash

# Default working directory
WORKDIR /root

# Default command (no browser)
CMD ["stash", "--nobrowser"]

