FROM ubuntu:25.10

RUN echo "deb http://ubuntu.ethz.ch/ubuntu/ noble main restricted universe multiverse" > /etc/apt/sources.list && \
    echo "deb http://ubuntu.ethz.ch/ubuntu/ noble-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://ubuntu.ethz.ch/ubuntu/ noble-security main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://ubuntu.ethz.ch/ubuntu/ noble-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
    apt update

RUN apt update && apt install -y \
    xvfb \
    libgtk-3-0 \
    unzip \
    xz-utils \
    wget \
    autoconf \
    pkg-config \
    build-essential \
    curl \
    libpng-dev \
    zip \
    git \
    git-lfs \
    jq \
    fonts-urw-base35 \
    libfreetype6-dev \
    libfontconfig1-dev \
    ghostscript \
    openssh-client \
    fonts-noto-color-emoji \
    fonts-dejavu-core \
    libxml2 \
    libxml2-dev \
    webp \
    && fc-cache -f -v \
    && apt clean \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /app/danser/songs \
    /app/danser/settings \
    /app/danser/videos \
    /app/danser/screenshots

RUN DAN_URL=$(curl -s https://api.github.com/repos/Wieku/danser-go/releases/latest \
    | jq -r '.assets[] | select(.name | endswith("linux.zip")) | .browser_download_url') && \
    wget -qO /tmp/danser.zip "$DAN_URL" && \
    unzip /tmp/danser.zip -d /app/danser && \
    chmod +x /app/danser/danser-cli && \
    rm -r /app/danser/ffmpeg

RUN wget -qO- $(curl -s https://api.github.com/repos/BtbN/FFmpeg-Builds/releases/latest \
    | grep "browser_download_url.*linux64-gpl-shared.tar.xz" \
    | cut -d '"' -f 4) -O /tmp/ffmpeg.tar.xz && \
    tar -xvf /tmp/ffmpeg.tar.xz -C /tmp && \
    mv /tmp/ffmpeg-*/bin/* /usr/local/bin/ && \
    mv /tmp/ffmpeg-*/lib/* /usr/local/lib/ && \
    mv /tmp/ffmpeg-*/include/* /usr/local/include/ && \
    mkdir -p /app/danser/ffmpeg && \
    cp /usr/local/bin/ffmpeg /app/danser/ffmpeg/ && \
    cp /usr/local/bin/ffprobe /app/danser/ffmpeg/ && \
    cp /usr/local/bin/ffplay /app/danser/ffmpeg/ && \
    ldconfig

RUN IMAGICK_URL=$(curl -s https://api.github.com/repos/ImageMagick/ImageMagick/releases/latest \
    | jq -r '.tarball_url') && \
    wget -qO- "$IMAGICK_URL" | tar xz && \
    cd ImageMagick-* && \
    ./configure --prefix=/usr/local \
    --with-bzlib=yes \
    --with-fontconfig=yes \
    --with-freetype=yes \
    --with-gslib=yes \
    --with-gvc=yes \
    --with-jpeg=yes \
    --with-jp2=yes \
    --with-png=yes \
    --with-tiff=yes \
    --with-xml=yes \
    --with-gs-font-dir=yes && \
    make -j$(nproc) && \
    make install && \
    ldconfig /usr/local/lib/ && \
    cd / && rm -rf ImageMagick-*

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && npm install -g npm@latest \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /app/danser/custom-replays/

RUN mkdir -p /app/danser/skins/default-skin/

COPY src/maps/* /app/danser/songs/

COPY src/replays/* /app/danser/custom-replays/

COPY src/settings/* /app/danser/settings/

COPY src/default-skin/ /app/danser/skins/default-skin/

WORKDIR /app/danser
