content: # This is based on https://github.com/scottyhardy/docker-remote-desktop/tree/master,
  # licensed under the MIT license.
  
  # Build xrdp pulseaudio modules in builder container
  # See https://github.com/neutrinolabs/pulseaudio-module-xrdp/wiki/README
  ARG TAG=24.04
  FROM ubuntu:$TAG as builder
  
  RUN sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources \
      && apt-get update \
      && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
          build-essential \
          dpkg-dev \
          git \
          libpulse-dev \
          pulseaudio \
      && apt-get build-dep -y pulseaudio \
      && apt-get source pulseaudio \
      && rm -rf /var/lib/apt/lists/*
  
  RUN cd /pulseaudio-$(pulseaudio --version | awk '{print $2}')* \
      && mkdir build \
      && meson build \
      && DIR_NAME=$(pwd) && cd .. && mv $DIR_NAME /pulse-build
  
  RUN git clone https://github.com/neutrinolabs/pulseaudio-module-xrdp.git /pulseaudio-module-xrdp \
      && cd /pulseaudio-module-xrdp \
      && ./bootstrap \
      && ./configure PULSE_DIR=/pulse-build \
      && make \
      && make install
  
  
  # Build the final image
  FROM ubuntu:$TAG
  
  RUN apt-get update \
      && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
          dbus-x11 \
          firefox \
          git \
          locales \
          pavucontrol \
          pulseaudio \
          pulseaudio-utils \
          sudo \
          x11-xserver-utils \
          xfce4 \
          xfce4-goodies \
          xfce4-pulseaudio-plugin \
          xorgxrdp \
          xrdp \
          xubuntu-icon-theme \
      && rm -rf /var/lib/apt/lists/*
  
  RUN sed -i -E 's/^; autospawn =.*/autospawn = yes/' /etc/pulse/client.conf \
      && [ -f /etc/pulse/client.conf.d/00-disable-autospawn.conf ] && sed -i -E 's/^(autospawn=.*)/# \1/' /etc/pulse/client.conf.d/00-disable-autospawn.conf || : \
      && locale-gen en_US.UTF-8
  
  RUN echo "enable_dynamic_resizing=true" >> /etc/xrdp/xrdp.ini
  
  ENV LANG en_US.UTF-8
  
  COPY --from=builder /usr/lib/pulse-*/modules/module-xrdp-sink.so /usr/lib/pulse-*/modules/module-xrdp-source.so /var/lib/xrdp-pulseaudio-installer/
  COPY rdp-entrypoint.sh /usr/bin/entrypoint
  EXPOSE 3389/tcp
  ENTRYPOINT ["/usr/bin/entrypoint"]
  