# 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

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"]