From 7f737322b00ee9aefb68cb774915d522ba4cb78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Molinero=20Fern=C3=A1ndez?= Date: Thu, 12 Dec 2019 16:19:01 +0100 Subject: [PATCH] Updated xorgxrdp to v0.2.12 and enabled glamor for hardware acceleration without VirtualGL --- Dockerfile.m4 | 48 +++++++++------------------ README.md | 19 ++++++----- config/xrdp/sesman.ini | 9 ----- run-with-virtualgl.sh | 49 ++++++++++++++++++++++++++++ run.sh | 5 ++- scripts/bin/container-foreground-cmd | 11 +++++-- 6 files changed, 86 insertions(+), 55 deletions(-) create mode 100755 run-with-virtualgl.sh diff --git a/Dockerfile.m4 b/Dockerfile.m4 index dbe0c65..c6be2fe 100644 --- a/Dockerfile.m4 +++ b/Dockerfile.m4 @@ -31,8 +31,11 @@ m4_ifelse(ENABLE_32BIT, 1, [[m4_dnl flex \ git \ intltool \ + libegl1-mesa-dev \ + libepoxy-dev \ libfdk-aac-dev \ libfuse-dev \ + libgbm-dev \ libgl1-mesa-dev \ libglu1-mesa-dev \ libmp3lame-dev \ @@ -63,6 +66,7 @@ m4_ifelse(ENABLE_32BIT, 1, [[m4_dnl xutils-dev \ m4_ifelse(ENABLE_32BIT, 1, [[m4_dnl g++-multilib \ + libegl1-mesa-dev:i386 \ libgl1-mesa-dev:i386 \ libglu1-mesa-dev:i386 \ libxtst-dev:i386 \ @@ -144,28 +148,6 @@ RUN make deb RUN dpkg -i ./virtualgl32_*.deb ]])m4_dnl -# Build TurboVNC -#ARG TURBOVNC_TREEISH= -#ARG TURBOVNC_REMOTE=https://github.com/TurboVNC/turbovnc.git -#RUN mkdir /tmp/turbovnc/ -#WORKDIR /tmp/turbovnc/ -#RUN git clone "${TURBOVNC_REMOTE:?}" ./ -#RUN git checkout "${TURBOVNC_TREEISH:?}" -#RUN git submodule update --init --recursive -#RUN mkdir /tmp/turbovnc/build/ -#WORKDIR /tmp/turbovnc/build/ -#RUN cmake ./ \ -# -G 'Unix Makefiles' \ -# -D PKGNAME=turbovnc \ -# -D CMAKE_BUILD_TYPE=Release \ -# -D CMAKE_INSTALL_PREFIX=/opt/TurboVNC \ -# -D CMAKE_POSITION_INDEPENDENT_CODE=1 \ -# -D TVNC_BUILDJAVA=0 \ -# ../ -#RUN make -j"$(nproc)" -#RUN make deb -#RUN dpkg -i ./turbovnc_*.deb - # Build XRDP ARG XRDP_TREEISH=v0.9.11 ARG XRDP_REMOTE=https://github.com/neutrinolabs/xrdp.git @@ -188,7 +170,7 @@ RUN make -j"$(nproc)" RUN checkinstall --default --pkgname=xrdp --pkgversion=0 --pkgrelease=0 # Build xorgxrdp -ARG XORGXRDP_TREEISH=v0.2.11 +ARG XORGXRDP_TREEISH=v0.2.12 ARG XORGXRDP_REMOTE=https://github.com/neutrinolabs/xorgxrdp.git RUN mkdir /tmp/xorgxrdp/ WORKDIR /tmp/xorgxrdp/ @@ -196,7 +178,7 @@ RUN git clone "${XORGXRDP_REMOTE:?}" ./ RUN git checkout "${XORGXRDP_TREEISH:?}" RUN git submodule update --init --recursive RUN ./bootstrap -RUN ./configure +RUN ./configure --enable-glamor RUN make -j"$(nproc)" RUN checkinstall --default --pkgname=xorgxrdp --pkgversion=0 --pkgrelease=0 @@ -258,8 +240,11 @@ m4_ifelse(ENABLE_32BIT, 1, [[m4_dnl iproute2 \ iputils-ping \ less \ + libegl1 \ + libepoxy0 \ libexo-1-0 \ libfdk-aac1 \ + libgbm1 \ libgl1-mesa-dri \ libgl1-mesa-glx \ libglu1-mesa \ @@ -320,9 +305,10 @@ m4_ifelse(ENABLE_32BIT, 1, [[m4_dnl zip \ m4_ifelse(ENABLE_32BIT, 1, [[m4_dnl && apt-get install -y --no-install-recommends \ + libegl1:i386 \ libgl1-mesa-dri:i386 \ libgl1-mesa-glx:i386 \ - libglu1-mesa:i386 \ + libglu1:i386 \ libxtst6:i386 \ libxv1:i386 \ ocl-icd-libopencl1:i386 \ @@ -397,10 +383,6 @@ COPY --from=build --chown=root:root /tmp/virtualgl/build32/virtualgl32_*.deb /tm RUN dpkg -i /tmp/virtualgl32.deb && rm -f /tmp/virtualgl32.deb ]])m4_dnl -## Install TurboVNC from package -#COPY --from=build --chown=root:root /tmp/turbovnc/build/turbovnc_*.deb /tmp/turbovnc.deb -#RUN dpkg -i /tmp/turbovnc.deb && rm -f /tmp/turbovnc.deb - # Install XRDP from package COPY --from=build --chown=root:root /tmp/xrdp/xrdp_*.deb /tmp/xrdp.deb RUN dpkg -i /tmp/xrdp.deb && rm -f /tmp/xrdp.deb @@ -420,11 +402,11 @@ ENV UNPRIVILEGED_USER_NAME=guest ENV UNPRIVILEGED_USER_PASSWORD=password ENV UNPRIVILEGED_USER_GROUPS=audio,input,video ENV UNPRIVILEGED_USER_SHELL=/bin/bash -ENV DISABLE_GPU=false ENV RDP_TLS_KEY_PATH=/etc/xrdp/key.pem ENV RDP_TLS_CERT_PATH=/etc/xrdp/cert.pem +ENV ENABLE_SSHD=false +ENV ENABLE_VIRTUALGL=false ENV PATH=/opt/VirtualGL/bin:${PATH} -#ENV PATH=/opt/TurboVNC/bin:${PATH} ENV VGL_DISPLAY=:0 ## Workaround for AMDGPU X_GLXCreatePbuffer issue: ## https://github.com/VirtualGL/virtualgl/issues/85#issuecomment-480291529 @@ -488,7 +470,9 @@ COPY --chown=root:root config/xrdp/sesman.ini /etc/xrdp/sesman.ini # Copy services COPY --chown=root:root scripts/service/ /etc/sv/ -RUN find /etc/sv/ -type d -mindepth 1 -maxdepth 1 -exec ln -sv '{}' /etc/service/ ';' +RUN ln -sv /etc/sv/dbus-daemon /etc/service/ +RUN ln -sv /etc/sv/xrdp /etc/service/ +RUN ln -sv /etc/sv/xrdp-sesman /etc/service/ # Copy scripts COPY --chown=root:root scripts/bin/ /usr/local/bin/ diff --git a/README.md b/README.md index 6f31d8e..5a2ca10 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Xubuntu on Docker -A Docker image based on Ubuntu 18.04 with Xfce desktop environment, -[VirtualGL](https://github.com/VirtualGL/virtualgl), -[XRDP](https://github.com/neutrinolabs/xrdp) and -[XRDP PulseAudio module](https://github.com/neutrinolabs/pulseaudio-module-xrdp). +A Docker image based on Ubuntu 18.04 with the Xfce desktop environment, +[XRDP](https://github.com/neutrinolabs/xrdp), +[XRDP PulseAudio module](https://github.com/neutrinolabs/pulseaudio-module-xrdp) and +[VirtualGL](https://github.com/VirtualGL/virtualgl). ## Start an instance @@ -11,17 +11,19 @@ A Docker image based on Ubuntu 18.04 with Xfce desktop environment, docker run --detach \ --name xubuntu \ --publish 3389:3389/tcp \ + --shm-size 2g \ + --device /dev/dri \ hectormolinero/xubuntu:latest ``` > You will be able to connect to the container via RDP through 3389/tcp port. -> **Important:** if you use the `--privileged` option the container will be able to use the GPU with -VirtualGL, but this will conflict with the host X server. - > **Important:** some software (like Firefox) need the shared memory to be increased, if you encounter any problem related to this you may use the `--shm-size` option. +> **Important:** enabling VirtualGL support requires the `--privileged` option and the X server +required for VirtualGL will conflict with the host X server. + ## Environment variables * `UNPRIVILEGED_USER_UID`: unprivileged user UID (`1000` by default). @@ -30,7 +32,8 @@ encounter any problem related to this you may use the `--shm-size` option. * `UNPRIVILEGED_USER_PASSWORD`: unprivileged user password (`password` by default). * `UNPRIVILEGED_USER_GROUPS`: unprivileged user groups (`audio,input,video` by default). * `UNPRIVILEGED_USER_SHELL`: unprivileged user shell (`/bin/bash` by default). -* `DISABLE_GPU`: disable the GPU in the container (`false` by default). +* `ENABLE_SSHD`: enable SSH server in the container (`false` by default). +* `ENABLE_VIRTUALGL`: enable VirtualGL support in the container (`false` by default). ## License diff --git a/config/xrdp/sesman.ini b/config/xrdp/sesman.ini index 09c8332..763a823 100644 --- a/config/xrdp/sesman.ini +++ b/config/xrdp/sesman.ini @@ -33,15 +33,6 @@ param=-noreset param=-nolisten param=tcp -;[Xvnc] -;param=/opt/TurboVNC/bin/Xvnc -;param=-bs -;param=-nolisten -;param=tcp -;param=-localhost -;param=-dpi -;param=96 - [Chansrv] FuseMountName=.thinclient_drives diff --git a/run-with-virtualgl.sh b/run-with-virtualgl.sh new file mode 100755 index 0000000..01a59c8 --- /dev/null +++ b/run-with-virtualgl.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +set -eu +export LC_ALL=C + +DOCKER=$(command -v docker 2>/dev/null) + +IMAGE_REGISTRY=docker.io +IMAGE_NAMESPACE=hectormolinero +IMAGE_PROJECT=xubuntu +IMAGE_TAG=latest +IMAGE_NAME=${IMAGE_REGISTRY:?}/${IMAGE_NAMESPACE:?}/${IMAGE_PROJECT:?}:${IMAGE_TAG:?} +CONTAINER_NAME=${IMAGE_PROJECT:?} + +imageExists() { [ -n "$("${DOCKER:?}" images -q "${1:?}")" ]; } +containerExists() { "${DOCKER:?}" ps -af name="${1:?}" --format '{{.Names}}' | grep -Fxq "${1:?}"; } +containerIsRunning() { "${DOCKER:?}" ps -f name="${1:?}" --format '{{.Names}}' | grep -Fxq "${1:?}"; } + +if ! imageExists "${IMAGE_NAME:?}" && ! imageExists "${IMAGE_NAME#docker.io/}"; then + >&2 printf -- '%s\n' "\"${IMAGE_NAME:?}\" image doesn't exist!" + exit 1 +fi + +if containerIsRunning "${CONTAINER_NAME:?}"; then + printf -- '%s\n' "Stopping \"${CONTAINER_NAME:?}\" container..." + "${DOCKER:?}" stop "${CONTAINER_NAME:?}" >/dev/null +fi + +if containerExists "${CONTAINER_NAME:?}"; then + printf -- '%s\n' "Removing \"${CONTAINER_NAME:?}\" container..." + "${DOCKER:?}" rm "${CONTAINER_NAME:?}" >/dev/null +fi + +printf -- '%s\n' "Creating \"${CONTAINER_NAME:?}\" container..." +"${DOCKER:?}" run --detach \ + --name "${CONTAINER_NAME:?}" \ + --hostname "${CONTAINER_NAME:?}" \ + --restart on-failure:3 \ + --log-opt max-size=32m \ + --publish 3322:3322/tcp \ + --publish 3389:3389/tcp \ + --shm-size 2g \ + --privileged \ + --env ENABLE_SSHD=true \ + --env ENABLE_VIRTUALGL=true \ + "${IMAGE_NAME:?}" "$@" >/dev/null + +printf -- '%s\n\n' 'Done!' +exec "${DOCKER:?}" logs -f "${CONTAINER_NAME:?}" diff --git a/run.sh b/run.sh index 4aa836f..cbfc69b 100755 --- a/run.sh +++ b/run.sh @@ -37,10 +37,9 @@ printf -- '%s\n' "Creating \"${CONTAINER_NAME:?}\" container..." --hostname "${CONTAINER_NAME:?}" \ --restart on-failure:3 \ --log-opt max-size=32m \ - --publish 0.0.0.0:3322:3322/tcp \ - --publish 0.0.0.0:3389:3389/tcp \ - --privileged \ + --publish 3389:3389/tcp \ --shm-size 2g \ + --device /dev/dri \ "${IMAGE_NAME:?}" "$@" >/dev/null printf -- '%s\n\n' 'Done!' diff --git a/scripts/bin/container-foreground-cmd b/scripts/bin/container-foreground-cmd index e2b3760..2156d7c 100755 --- a/scripts/bin/container-foreground-cmd +++ b/scripts/bin/container-foreground-cmd @@ -33,9 +33,14 @@ unset UNPRIVILEGED_USER_PASSWORD # Dump environment variables export-env > /etc/profile.d/env.sh -# Disable xdummy if there is no graphics card -if [ "${DISABLE_GPU:?}" = 'true' ] || [ ! -d /dev/dri/ ]; then - unlink /etc/service/xdummy +# Enable sshd service if ENABLE_SSHD is true +if [ "${ENABLE_SSHD:?}" = 'true' ]; then + ln -s /etc/sv/sshd /etc/service/ +fi + +# Enable xdummy service if ENABLE_VIRTUALGL is true +if [ "${ENABLE_VIRTUALGL:?}" = 'true' ]; then + ln -s /etc/sv/xdummy /etc/service/ fi # Create RANDFILE if it does not exist