FROM ubuntu:26.04
ENV DEBIAN_FRONTEND=noninteractive

# Install unzip first so we can extract the large static zips
RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*

# Copy and extract large static files first
COPY nosteam.zip /home/ubuntu/
COPY wine_user_folder.zip /home/ubuntu/
RUN cd /home/ubuntu && unzip nosteam.zip && rm nosteam.zip && unzip wine_user_folder.zip && rm wine_user_folder.zip

# Install all packages
RUN dpkg --add-architecture i386 && \
    apt-get update && \
    apt-get install -y \
    wget \
    gnupg2 \
    ca-certificates \
    && mkdir -pm755 /etc/apt/keyrings \
    && wget -O- https://dl.winehq.org/wine-builds/winehq.key | gpg --dearmor -o /etc/apt/keyrings/winehq-archive.key \
    && echo "deb [signed-by=/etc/apt/keyrings/winehq-archive.key] https://dl.winehq.org/wine-builds/ubuntu/ resolute main" > /etc/apt/sources.list.d/winehq.list \
    && apt-get update \
    && apt-get install -y --install-recommends winehq-stable \
    && apt-get install -y \
    winetricks \
    weston \
    xwayland \
    dbus-x11 \
    pipewire \
    pipewire-pulse \
    pipewire-audio-client-libraries \
    wireplumber \
    pulseaudio-utils \
    ffmpeg \
    xdotool \
    nodejs \
    socat \
    npm \
    mesa-vulkan-drivers \
    vulkan-tools \
    gstreamer1.0-tools \
    gstreamer1.0-plugins-base \
    gstreamer1.0-plugins-good \
    gstreamer1.0-plugins-bad \
    gstreamer1.0-plugins-ugly \
    gstreamer1.0-libav \
    gstreamer1.0-nice \
    gstreamer1.0-pipewire \
    gir1.2-gst-plugins-bad-1.0 \
    python3-gi \
    python3-gst-1.0 \
    python3-pip \
    && rm -rf /var/lib/apt/lists/*

# Environment variables
ENV VK_ICD_FILENAMES="/usr/share/vulkan/icd.d/lvp_icd.json"
ENV XDG_RUNTIME_DIR=/tmp/weston-runtime
ENV WAYLAND_DISPLAY=wayland-0
ENV DISPLAY=:99
ENV LP_NATIVE_VECTOR_WIDTH=256
ENV MESA_SHADER_CACHE_DIR=/home/ubuntu/.cache/mesa_shader_cache
ENV MESA_SHADER_CACHE_MAX_SIZE=10G

# Copy frequently changing files last
COPY start.sh /home/ubuntu/start.sh
COPY streaming-agent/ /home/ubuntu/streaming-agent/
RUN cd /home/ubuntu/streaming-agent && npm install
RUN pip3 install --break-system-packages -r /home/ubuntu/streaming-agent/requirements.txt
RUN chown -R ubuntu:ubuntu /home/ubuntu/
RUN chmod +x /home/ubuntu/start.sh
USER ubuntu
WORKDIR /home/ubuntu
CMD ["/bin/bash", "/home/ubuntu/start.sh"]
