FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

# Install PipeWire, WirePlumber, PulseAudio compat, ALSA, and D-Bus
RUN apt-get update && apt-get install -y \
    pipewire \
    pipewire-pulse \
    pipewire-alsa \
    wireplumber \
    dbus-x11 \
    curl \
    udev \
    alsa-utils \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Download the precompiled binary based on architecture
RUN ARCH=$(uname -m) && \
    if [ "$ARCH" = "aarch64" ]; then \
        curl -L -o pipewire-web-remote https://github.com/oudeis01/pipewire-web-remote/releases/latest/download/pipewire-web-remote-aarch64; \
    elif [ "$ARCH" = "x86_64" ]; then \
        curl -L -o pipewire-web-remote https://github.com/oudeis01/pipewire-web-remote/releases/latest/download/pipewire-web-remote-x86_64; \
    else \
        echo "Unsupported architecture"; exit 1; \
    fi && \
    chmod +x pipewire-web-remote

COPY start.sh /start.sh
RUN chmod +x /start.sh

# The Web UI defaults to 8080
EXPOSE 8080

CMD ["/start.sh"]
