# syntax=docker/dockerfile:1.7

ARG SUNSHINE_VERSION=v2025.924.154138

# On récupère le paquet Sunshine depuis l'image officielle.
FROM ghcr.io/lizardbyte/sunshine:${SUNSHINE_VERSION}-ubuntu-24.04 AS sunshine

# PoC : on réutilise volontairement notre environnement graphique déjà validé.
FROM image-registry.openshift-image-registry.svc:5000/desktop/desktop:latest

USER root

# L'image Sunshine officielle conserve le .deb utilisé pour installer Sunshine.
COPY --from=sunshine /sunshine.deb /tmp/sunshine.deb

RUN apt-get update \
    && apt-get install --no-install-recommends -y /tmp/sunshine.deb \
    && rm -f /tmp/sunshine.deb \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /var/cache/apt/*

COPY sunshine-entrypoint.sh /etc/sunshine-entrypoint.sh

RUN sed -i 's/\r$//' /etc/sunshine-entrypoint.sh \
    && chmod 0755 /etc/sunshine-entrypoint.sh

# Steam / Proton
RUN dpkg --add-architecture i386 \
    && apt-get update \
    && apt-get install --no-install-recommends -y \
        ca-certificates \
        curl \
    && curl -fsSL \
        https://repo.steampowered.com/steam/archive/stable/steam.gpg \
        -o /usr/share/keyrings/steam.gpg \
    && printf '%s\n' \
        'deb [arch=amd64,i386 signed-by=/usr/share/keyrings/steam.gpg] https://repo.steampowered.com/steam/ stable steam' \
        > /etc/apt/sources.list.d/steam-bootstrap.list \
    && apt-get update \
    && apt-get install --no-install-recommends -y \
        libgl1:amd64 \
        libgl1:i386 \
        libgl1-mesa-dri:amd64 \
        libgl1-mesa-dri:i386 \
        libglx-mesa0:amd64 \
        libglx-mesa0:i386 \
        libvulkan1:amd64 \
        libvulkan1:i386 \
        steam-launcher \
    && rm -f /etc/apt/sources.list.d/steam-bootstrap.list \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /var/cache/apt/*

USER 1000:1000

ENV DISPLAY=:20 \
    HOME=/home/ubuntu \
    USER=ubuntu \
    XDG_RUNTIME_DIR=/tmp/runtime-ubuntu \
    PIPEWIRE_RUNTIME_DIR=/tmp/runtime-ubuntu \
    PULSE_RUNTIME_PATH=/tmp/runtime-ubuntu/pulse \
    PULSE_SERVER=unix:/tmp/runtime-ubuntu/pulse/native \
    NVIDIA_VISIBLE_DEVICES=all \
    NVIDIA_DRIVER_CAPABILITIES=all

WORKDIR /home/ubuntu

EXPOSE 47984-47990/tcp
EXPOSE 48010/tcp
EXPOSE 47998-48000/udp

ENTRYPOINT ["/etc/sunshine-entrypoint.sh"]