Dockerfile 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. # syntax=docker/dockerfile:1.7
  2. # Final target:
  3. # Ubuntu 24.04 + NVIDIA GLX + XFCE + PipeWire + Firefox + Selkies
  4. #
  5. # The build uses intermediate stages, but produces a single final image.
  6. ARG DISTRIB_RELEASE=24.04
  7. ARG SELKIES_IMAGE=ghcr.io/selkies-project/selkies/py-build:main
  8. ARG SELKIES_GIT_REF=main
  9. ARG NVIDIA_VAAPI_DRIVER_VERSION=latest
  10. # -----------------------------------------------------------------------------
  11. # Current Selkies wheel
  12. # -----------------------------------------------------------------------------
  13. FROM ${SELKIES_IMAGE} AS selkies-build
  14. # -----------------------------------------------------------------------------
  15. # Selkies joystick interposer
  16. # -----------------------------------------------------------------------------
  17. # Build the Selkies joystick interposer directly from its official source.
  18. FROM docker.io/library/ubuntu:${DISTRIB_RELEASE} AS selkies-js-interposer-builder
  19. ARG DEBIAN_FRONTEND=noninteractive
  20. ARG SELKIES_GIT_REF
  21. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  22. RUN apt-get update \
  23. && apt-get install --no-install-recommends -y \
  24. build-essential \
  25. ca-certificates \
  26. curl \
  27. && rm -rf /var/lib/apt/lists/*
  28. RUN set -eux; \
  29. curl -fsSL \
  30. "https://raw.githubusercontent.com/selkies-project/selkies/${SELKIES_GIT_REF}/addons/js-interposer/joystick_interposer.c" \
  31. -o /tmp/joystick_interposer.c; \
  32. install -d -m 0755 /out; \
  33. gcc -shared -fPIC -O2 \
  34. -Wl,-z,relro,-z,now \
  35. -o /out/selkies_joystick_interposer.so \
  36. /tmp/joystick_interposer.c \
  37. -ldl; \
  38. test -s /out/selkies_joystick_interposer.so
  39. # -----------------------------------------------------------------------------
  40. # Build the Selkies Python environment
  41. # -----------------------------------------------------------------------------
  42. FROM docker.io/library/ubuntu:${DISTRIB_RELEASE} AS selkies-runtime-builder
  43. ARG DEBIAN_FRONTEND=noninteractive
  44. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  45. COPY --from=selkies-build /opt/pypi/dist/selkies-*.whl /tmp/
  46. RUN apt-get update \
  47. && apt-get install --no-install-recommends -y \
  48. build-essential \
  49. libsm6 \
  50. libopus0 \
  51. libpulse0 \
  52. libxkbcommon-dev \
  53. pkg-config \
  54. python3 \
  55. python3-dev \
  56. python3-pip \
  57. python3-venv \
  58. && python3 -m venv /opt/selkies \
  59. && /opt/selkies/bin/python -m pip install \
  60. --no-cache-dir \
  61. --upgrade \
  62. pip \
  63. setuptools \
  64. wheel \
  65. && printf '%s\n' \
  66. 'pixelflux==1.6.4' \
  67. 'pcmflux==1.0.8' \
  68. > /tmp/selkies-constraints.txt \
  69. && /opt/selkies/bin/python -m pip install \
  70. --no-cache-dir \
  71. --force-reinstall \
  72. --constraint /tmp/selkies-constraints.txt \
  73. /tmp/selkies-*.whl
  74. # -----------------------------------------------------------------------------
  75. # Build the current nvidia-vaapi-driver without retaining build dependencies
  76. # -----------------------------------------------------------------------------
  77. FROM docker.io/library/ubuntu:${DISTRIB_RELEASE} AS nvidia-vaapi-builder
  78. ARG DEBIAN_FRONTEND=noninteractive
  79. ARG NVIDIA_VAAPI_DRIVER_VERSION
  80. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  81. RUN apt-get update \
  82. && apt-get install --no-install-recommends -y \
  83. ca-certificates \
  84. curl \
  85. gcc \
  86. jq \
  87. meson \
  88. ninja-build \
  89. pkg-config \
  90. libdrm-dev \
  91. libegl-dev \
  92. libffmpeg-nvenc-dev \
  93. libgstreamer-plugins-bad1.0-dev \
  94. libva-dev \
  95. && rm -rf /var/lib/apt/lists/*
  96. RUN set -eux; \
  97. version="${NVIDIA_VAAPI_DRIVER_VERSION}"; \
  98. if [[ "${version}" == "latest" ]]; then \
  99. version="$(curl -fsSL https://api.github.com/repos/elFarto/nvidia-vaapi-driver/releases/latest \
  100. | jq -r '.tag_name' \
  101. | sed 's/^v//')"; \
  102. fi; \
  103. curl -fsSL \
  104. "https://github.com/elFarto/nvidia-vaapi-driver/archive/refs/tags/v${version}.tar.gz" \
  105. -o /tmp/nvidia-vaapi-driver.tar.gz; \
  106. mkdir -p /tmp/nvidia-vaapi-driver; \
  107. tar -xzf /tmp/nvidia-vaapi-driver.tar.gz \
  108. --strip-components=1 \
  109. -C /tmp/nvidia-vaapi-driver; \
  110. cd /tmp/nvidia-vaapi-driver; \
  111. meson setup build \
  112. --prefix=/usr \
  113. --buildtype=release; \
  114. meson compile -C build; \
  115. DESTDIR=/out meson install -C build
  116. # -----------------------------------------------------------------------------
  117. # Build the Selkies web frontend from the official source repository
  118. # -----------------------------------------------------------------------------
  119. FROM docker.io/library/node:22-bookworm-slim AS selkies-web-builder
  120. ARG DEBIAN_FRONTEND=noninteractive
  121. ARG SELKIES_GIT_REF=main
  122. ARG SELKIES_MODE=websockets
  123. ARG SELKIES_UPLOAD_DIR=/home/ubuntu/Desktop
  124. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  125. RUN apt-get update \
  126. && apt-get install --no-install-recommends -y \
  127. ca-certificates \
  128. cmake \
  129. curl \
  130. git \
  131. && rm -rf /var/lib/apt/lists/*
  132. WORKDIR /tmp/selkies
  133. RUN curl -fsSL \
  134. "https://github.com/selkies-project/selkies/archive/${SELKIES_GIT_REF}.tar.gz" \
  135. -o /tmp/selkies.tar.gz \
  136. && tar -xzf /tmp/selkies.tar.gz \
  137. --strip-components=1 \
  138. -C /tmp/selkies \
  139. && rm -f /tmp/selkies.tar.gz
  140. RUN set -eux; \
  141. cd /tmp/selkies/addons/selkies-web-core; \
  142. npm install; \
  143. npm run build; \
  144. \
  145. cd /tmp/selkies/addons/selkies-dashboard; \
  146. cp ../selkies-web-core/dist/selkies-core.js src/; \
  147. npm install; \
  148. SELKIES_INJECT=1 \
  149. SELKIES_MODE="${SELKIES_MODE}" \
  150. SELKIES_UPLOAD_DIR="${SELKIES_UPLOAD_DIR}" \
  151. npm run build; \
  152. \
  153. mkdir -p dist/src; \
  154. cp ../selkies-web-core/dist/selkies-core.js dist/src/; \
  155. cp ../universal-touch-gamepad/universalTouchGamepad.js dist/src/; \
  156. cp -r ../selkies-web-core/dist/jsdb dist/; \
  157. \
  158. mkdir -p /out; \
  159. cp -a dist/. /out/; \
  160. test -f /out/index.html
  161. # -----------------------------------------------------------------------------
  162. # Build the legacy Pixelflux capture library required by pixelflux 1.6.4
  163. # -----------------------------------------------------------------------------
  164. FROM docker.io/library/ubuntu:${DISTRIB_RELEASE} AS pixelflux-legacy-builder
  165. ARG DEBIAN_FRONTEND=noninteractive
  166. ARG PIXELFLUX_VERSION=1.6.4
  167. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  168. RUN apt-get update \
  169. && apt-get install --no-install-recommends -y \
  170. ca-certificates \
  171. curl \
  172. g++ \
  173. pkg-config \
  174. libavcodec-dev \
  175. libavutil-dev \
  176. libdrm-dev \
  177. libjpeg-dev \
  178. libva-dev \
  179. libx11-dev \
  180. libx264-dev \
  181. libxext-dev \
  182. libxfixes-dev \
  183. libyuv-dev \
  184. && rm -rf /var/lib/apt/lists/*
  185. WORKDIR /tmp/pixelflux
  186. RUN set -eux; \
  187. curl -fsSL \
  188. "https://codeload.github.com/linuxserver/pixelflux/tar.gz/refs/tags/${PIXELFLUX_VERSION}" \
  189. -o /tmp/pixelflux.tar.gz; \
  190. tar -xzf /tmp/pixelflux.tar.gz \
  191. --strip-components=1 \
  192. -C /tmp/pixelflux; \
  193. install -d -m 0755 /out; \
  194. test -f /usr/include/va/va.h; \
  195. test -f /usr/include/va/va_drm.h; \
  196. test -f /usr/include/libdrm/drm.h; \
  197. pkg-config --exists \
  198. libavcodec \
  199. libavutil \
  200. libva \
  201. libdrm \
  202. x11 \
  203. xext \
  204. xfixes; \
  205. g++ \
  206. -std=c++17 \
  207. -Wno-unused-function \
  208. -fPIC \
  209. -O2 \
  210. -shared \
  211. -Ipixelflux/include \
  212. -o /out/screen_capture_module.so \
  213. pixelflux/screen_capture_module.cpp \
  214. pixelflux/include/xxhash.c \
  215. -lX11 \
  216. -lXext \
  217. -lXfixes \
  218. -ljpeg \
  219. -lx264 \
  220. -lyuv \
  221. -ldl \
  222. -lavcodec \
  223. -lavutil; \
  224. test -s /out/screen_capture_module.so; \
  225. ldd /out/screen_capture_module.so | tee /tmp/pixelflux-ldd.txt; \
  226. if grep -q "not found" /tmp/pixelflux-ldd.txt; then \
  227. echo "Missing Pixelflux shared-library dependency"; \
  228. exit 1; \
  229. fi
  230. # -----------------------------------------------------------------------------
  231. # Final image
  232. # -----------------------------------------------------------------------------
  233. FROM docker.io/library/ubuntu:${DISTRIB_RELEASE}
  234. ARG DEBIAN_FRONTEND=noninteractive
  235. ARG DISTRIB_RELEASE
  236. ARG TZ=UTC
  237. ARG USER_NAME=ubuntu
  238. ARG USER_UID=1000
  239. ARG USER_GID=1000
  240. LABEL org.opencontainers.image.title="Selkies NVIDIA XFCE Desktop" \
  241. org.opencontainers.image.description="XFCE remote desktop with Selkies, PipeWire and NVIDIA acceleration" \
  242. org.opencontainers.image.source="https://github.com/selkies-project/selkies"
  243. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  244. ENV TZ="${TZ}" \
  245. LANG="en_US.UTF-8" \
  246. LANGUAGE="en_US:en" \
  247. LC_ALL="en_US.UTF-8" \
  248. PASSWD="mypasswd" \
  249. DISPLAY=":20" \
  250. DISPLAY_SIZEW="1920" \
  251. DISPLAY_SIZEH="1080" \
  252. DISPLAY_REFRESH="60" \
  253. DISPLAY_DPI="96" \
  254. DISPLAY_CDEPTH="24" \
  255. VIDEO_PORT="DFP" \
  256. DESKTOP_SESSION="xfce" \
  257. XDG_SESSION_DESKTOP="xfce" \
  258. XDG_CURRENT_DESKTOP="XFCE" \
  259. XDG_SESSION_TYPE="x11" \
  260. SELKIES_MODE="websockets" \
  261. SELKIES_PORT="8081" \
  262. SELKIES_ENCODER="x264enc" \
  263. SELKIES_ENABLE_RESIZE="false" \
  264. SELKIES_ENABLE_BASIC_AUTH="true" \
  265. NVIDIA_VISIBLE_DEVICES="all" \
  266. NVIDIA_DRIVER_CAPABILITIES="all" \
  267. __GL_SYNC_TO_VBLANK="0" \
  268. __GLX_VENDOR_LIBRARY_NAME="nvidia" \
  269. LIBVA_DRIVER_NAME="nvidia" \
  270. NVD_BACKEND="direct" \
  271. MOZ_DISABLE_RDD_SANDBOX="1" \
  272. MOZ_X11_EGL="1" \
  273. PIPEWIRE_LATENCY="128/48000" \
  274. XDG_RUNTIME_DIR="/tmp/runtime-ubuntu" \
  275. PIPEWIRE_RUNTIME_DIR="/tmp/runtime-ubuntu" \
  276. PULSE_RUNTIME_PATH="/tmp/runtime-ubuntu/pulse" \
  277. PULSE_SERVER="unix:/tmp/runtime-ubuntu/pulse/native" \
  278. DBUS_SYSTEM_BUS_ADDRESS="unix:path=/tmp/runtime-ubuntu/dbus-system-bus" \
  279. APPIMAGE_EXTRACT_AND_RUN="1" \
  280. SUDO_EDITOR="mousepad"
  281. # Bootstrap packages needed to configure APT repositories.
  282. RUN apt-get update \
  283. && apt-get install --no-install-recommends -y \
  284. ca-certificates \
  285. curl \
  286. gnupg \
  287. locales \
  288. ssl-cert \
  289. tzdata \
  290. && locale-gen en_US.UTF-8 fr_FR.UTF-8 \
  291. && ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime \
  292. && echo "${TZ}" > /etc/timezone \
  293. && rm -rf /var/lib/apt/lists/*
  294. # Keep the same Mozilla and PipeWire repositories as the original image.
  295. RUN install -d -m 0755 \
  296. /etc/apt/preferences.d \
  297. /etc/apt/sources.list.d \
  298. /etc/apt/trusted.gpg.d \
  299. && printf '%s\n' \
  300. 'Package: firefox*' \
  301. 'Pin: version 1:1snap*' \
  302. 'Pin-Priority: -1' \
  303. > /etc/apt/preferences.d/firefox-nosnap \
  304. && curl -fsSL \
  305. 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x738BEB9321D1AAEC13EA9391AEBDF4819BE21867' \
  306. | gpg --dearmor \
  307. > /etc/apt/trusted.gpg.d/mozillateam-ubuntu-ppa.gpg \
  308. && echo \
  309. "deb https://ppa.launchpadcontent.net/mozillateam/ppa/ubuntu noble main" \
  310. > /etc/apt/sources.list.d/mozillateam-ubuntu-ppa.list \
  311. && curl -fsSL \
  312. 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xFC43B7352BCC0EC8AF2EEB8B25088A0359807596' \
  313. | gpg --dearmor \
  314. > /etc/apt/trusted.gpg.d/pipewire-debian-ubuntu.gpg \
  315. && echo \
  316. "deb https://ppa.launchpadcontent.net/pipewire-debian/pipewire-upstream/ubuntu noble main" \
  317. > /etc/apt/sources.list.d/pipewire-upstream.list \
  318. && echo \
  319. "deb https://ppa.launchpadcontent.net/pipewire-debian/wireplumber-upstream/ubuntu noble main" \
  320. > /etc/apt/sources.list.d/wireplumber-upstream.list
  321. # Base system, desktop, Xorg, NVIDIA runtime interfaces and user tools.
  322. # There are deliberately no Intel/AMD VA-API or Vulkan drivers and no i386
  323. # architecture.
  324. RUN apt-get update \
  325. && apt-get install --no-install-recommends -y \
  326. apt-utils \
  327. bash-completion \
  328. binutils \
  329. btop \
  330. bzip2 \
  331. clinfo \
  332. dbus-user-session \
  333. dbus-x11 \
  334. desktop-file-utils \
  335. dnsutils \
  336. file \
  337. firefox \
  338. fonts-dejavu \
  339. fonts-liberation \
  340. fonts-noto \
  341. fonts-noto-cjk \
  342. fonts-noto-color-emoji \
  343. fonts-noto-mono \
  344. fonts-ubuntu \
  345. fuse \
  346. git \
  347. gvfs \
  348. jq \
  349. kmod \
  350. less \
  351. libdrm2 \
  352. libegl1 \
  353. libelf-dev \
  354. libgcrypt20 \
  355. libgl1 \
  356. libgles1 \
  357. libgles2 \
  358. libglu1-mesa \
  359. libglvnd-dev \
  360. libglvnd0 \
  361. libglx0 \
  362. libgstreamer-plugins-bad1.0-0 \
  363. libopengl0 \
  364. libopus0 \
  365. libpci3 \
  366. libpulse0 \
  367. libsm6 \
  368. libva-drm2 \
  369. libva-x11-2 \
  370. libva2 \
  371. libvulkan1 \
  372. libx11-6 \
  373. libx11-xcb1 \
  374. libxau6 \
  375. libxcb-dri3-0 \
  376. libxcb1 \
  377. libxdamage1 \
  378. libxdmcp6 \
  379. libxext6 \
  380. libxfixes3 \
  381. libxkbcommon0 \
  382. libxtst6 \
  383. libxv1 \
  384. mousepad \
  385. nano \
  386. neofetch \
  387. net-tools \
  388. ocl-icd-libopencl1 \
  389. pavucontrol \
  390. pciutils \
  391. procps \
  392. psmisc \
  393. python3 \
  394. python3-pip \
  395. python3-venv \
  396. ristretto \
  397. sudo \
  398. supervisor \
  399. thunar \
  400. tumbler \
  401. udev \
  402. unzip \
  403. vainfo \
  404. vim \
  405. vulkan-tools \
  406. wget \
  407. wmctrl \
  408. x11-apps \
  409. x11-utils \
  410. x11-xkb-utils \
  411. x11-xserver-utils \
  412. x264 \
  413. x265 \
  414. xauth \
  415. xbitmaps \
  416. xclip \
  417. xcvt \
  418. xdg-user-dirs \
  419. xdg-utils \
  420. xfce4 \
  421. xfce4-goodies \
  422. xfce4-notifyd \
  423. xfce4-pulseaudio-plugin \
  424. xfce4-terminal \
  425. xfonts-base \
  426. xfonts-scalable \
  427. xinit \
  428. xkb-data \
  429. xsel \
  430. xserver-xorg-core \
  431. xserver-xorg-input-libinput \
  432. xserver-xorg-legacy \
  433. xsettingsd \
  434. xterm \
  435. xdotool \
  436. xz-utils \
  437. zip \
  438. zstd \
  439. pipewire \
  440. pipewire-alsa \
  441. pipewire-audio-client-libraries \
  442. pipewire-jack \
  443. pipewire-libcamera \
  444. pipewire-locales \
  445. pipewire-v4l2 \
  446. pipewire-vulkan \
  447. gstreamer1.0-libcamera \
  448. gstreamer1.0-pipewire \
  449. gir1.2-wp-0.5 \
  450. libpipewire-0.3-modules \
  451. libpipewire-module-x11-bell \
  452. libspa-0.2-bluetooth \
  453. libspa-0.2-jack \
  454. libspa-0.2-modules \
  455. wireplumber \
  456. wireplumber-locales \
  457. apache2-utils \
  458. nginx \
  459. netcat-openbsd \
  460. libavcodec60 \
  461. libavutil58 \
  462. libjpeg-turbo8 \
  463. libx264-164 \
  464. libyuv0 \
  465. && apt-get clean \
  466. && rm -rf \
  467. /var/lib/apt/lists/* \
  468. /var/cache/apt/* \
  469. /var/cache/debconf/* \
  470. /var/log/* \
  471. /tmp/* \
  472. /var/tmp/*
  473. # Install only the compiled NVIDIA VA-API runtime from the builder stage.
  474. COPY --from=nvidia-vaapi-builder /out/usr/ /usr/
  475. # Make NVIDIA libraries injected by NVIDIA Container Toolkit discoverable.
  476. RUN printf '%s\n' \
  477. '/usr/local/nvidia/lib' \
  478. '/usr/local/nvidia/lib64' \
  479. > /etc/ld.so.conf.d/nvidia.conf \
  480. && install -d -m 0755 \
  481. /etc/OpenCL/vendors \
  482. /etc/vulkan/icd.d \
  483. /usr/share/glvnd/egl_vendor.d \
  484. && echo 'libnvidia-opencl.so.1' \
  485. > /etc/OpenCL/vendors/nvidia.icd \
  486. && cat > /etc/vulkan/icd.d/nvidia_icd.json <<'EOF'
  487. {
  488. "file_format_version": "1.0.0",
  489. "ICD": {
  490. "library_path": "libGLX_nvidia.so.0",
  491. "api_version": "1.3.0"
  492. }
  493. }
  494. EOF
  495. RUN cat > /usr/share/glvnd/egl_vendor.d/10_nvidia.json <<'EOF'
  496. {
  497. "file_format_version": "1.0.0",
  498. "ICD": {
  499. "library_path": "libEGL_nvidia.so.0"
  500. }
  501. }
  502. EOF
  503. ENV PATH="/opt/selkies/bin:/usr/local/nvidia/bin:${PATH}" \
  504. LD_LIBRARY_PATH="/usr/local/nvidia/lib:/usr/local/nvidia/lib64"
  505. # Install the Selkies wheel from the official stable build image.
  506. COPY --from=selkies-runtime-builder /opt/selkies /opt/selkies
  507. COPY --from=pixelflux-legacy-builder \
  508. /out/screen_capture_module.so \
  509. /tmp/screen_capture_module.so
  510. RUN set -eux; \
  511. PIXELFLUX_DIR="$(/opt/selkies/bin/python -c \
  512. 'from pathlib import Path; import pixelflux; print(Path(pixelflux.__file__).resolve().parent)')"; \
  513. install -m 0755 \
  514. /tmp/screen_capture_module.so \
  515. "${PIXELFLUX_DIR}/screen_capture_module.so"; \
  516. ldd "${PIXELFLUX_DIR}/screen_capture_module.so"; \
  517. test -z "$(ldd "${PIXELFLUX_DIR}/screen_capture_module.so" | grep 'not found' || true)"; \
  518. rm -f /tmp/screen_capture_module.so
  519. COPY --chown=${USER_UID}:${USER_GID} \
  520. --from=selkies-web-builder \
  521. /out/ \
  522. /opt/selkies-web/
  523. COPY --from=selkies-js-interposer-builder \
  524. /out/selkies_joystick_interposer.so \
  525. /usr/local/lib/selkies_joystick_interposer.so
  526. RUN chmod 0755 /usr/local/lib/selkies_joystick_interposer.so
  527. # Create the regular desktop user. sudo-root is kept because Xorg and the
  528. # NVIDIA userspace installer need a few targeted root operations at runtime.
  529. RUN set -eux; \
  530. if ! getent group "${USER_NAME}" >/dev/null; then \
  531. groupadd --gid "${USER_GID}" "${USER_NAME}"; \
  532. fi; \
  533. if ! id -u "${USER_NAME}" >/dev/null 2>&1; then \
  534. useradd \
  535. --uid "${USER_UID}" \
  536. --gid "${USER_NAME}" \
  537. --create-home \
  538. --shell /bin/bash \
  539. "${USER_NAME}"; \
  540. else \
  541. usermod --shell /bin/bash "${USER_NAME}"; \
  542. fi; \
  543. for group in \
  544. adm audio cdrom dialout dip fax floppy games input lp plugdev render \
  545. ssl-cert sudo tape tty video voice; \
  546. do \
  547. getent group "${group}" >/dev/null \
  548. && usermod -aG "${group}" "${USER_NAME}" \
  549. || true; \
  550. done; \
  551. echo "${USER_NAME} ALL=(ALL:ALL) NOPASSWD: ALL" \
  552. > "/etc/sudoers.d/${USER_NAME}"; \
  553. chmod 0440 "/etc/sudoers.d/${USER_NAME}"; \
  554. echo "${USER_NAME}:${PASSWD}" | chpasswd; \
  555. cp -a /usr/bin/sudo /usr/bin/sudo-root; \
  556. chown root:root /usr/bin/sudo-root; \
  557. chmod 4755 /usr/bin/sudo-root; \
  558. install -d \
  559. -o "${USER_UID}" \
  560. -g "${USER_GID}" \
  561. -m 0700 \
  562. /tmp/runtime-ubuntu; \
  563. chown -R \
  564. "${USER_UID}:${USER_GID}" \
  565. "/home/${USER_NAME}" \
  566. /etc/X11 \
  567. /opt/selkies
  568. # XFCE defaults suitable for a permanently streamed desktop.
  569. RUN install -d -m 0755 \
  570. /etc/xdg/xfce4/xfconf/xfce-perchannel-xml \
  571. /etc/firefox/policies \
  572. && if [[ -f /etc/xdg/xfce4/panel/default.xml ]]; then \
  573. cp -f \
  574. /etc/xdg/xfce4/panel/default.xml \
  575. /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml; \
  576. fi \
  577. && cat > /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-power-manager.xml <<'EOF'
  578. <?xml version="1.0" encoding="UTF-8"?>
  579. <channel name="xfce4-power-manager" version="1.0">
  580. <property name="xfce4-power-manager" type="empty">
  581. <property name="blank-on-ac" type="int" value="0"/>
  582. <property name="dpms-enabled" type="bool" value="false"/>
  583. <property name="lock-screen-suspend-hibernate" type="bool" value="false"/>
  584. </property>
  585. </channel>
  586. EOF
  587. RUN cat > /etc/firefox/policies/policies.json <<'EOF'
  588. {
  589. "policies": {
  590. "Preferences": {
  591. "gfx.x11-egl.force-enabled": {
  592. "Value": true,
  593. "Status": "default"
  594. },
  595. "media.ffmpeg.vaapi.enabled": {
  596. "Value": true,
  597. "Status": "default"
  598. },
  599. "media.hardware-video-decoding.force-enabled": {
  600. "Value": true,
  601. "Status": "default"
  602. },
  603. "media.rdd-ffmpeg.enabled": {
  604. "Value": true,
  605. "Status": "default"
  606. }
  607. }
  608. }
  609. }
  610. EOF
  611. RUN update-alternatives --set x-www-browser /usr/bin/firefox \
  612. || true
  613. # The three files below must be placed beside this Dockerfile.
  614. COPY --chown=${USER_UID}:${USER_GID} entrypoint.sh /etc/entrypoint.sh
  615. COPY --chown=${USER_UID}:${USER_GID} selkies-entrypoint.sh /etc/selkies-entrypoint.sh
  616. COPY --chown=${USER_UID}:${USER_GID} supervisord.conf /etc/supervisord.conf
  617. COPY --chown=${USER_UID}:${USER_GID} nginx.conf /etc/nginx/nginx.conf
  618. COPY --chown=${USER_UID}:${USER_GID} nginx-entrypoint.sh /etc/nginx-entrypoint.sh
  619. RUN sed -i 's/\r$//' \
  620. /etc/entrypoint.sh \
  621. /etc/selkies-entrypoint.sh \
  622. /etc/nginx-entrypoint.sh \
  623. && chmod 0755 \
  624. /etc/entrypoint.sh \
  625. /etc/selkies-entrypoint.sh \
  626. /etc/nginx-entrypoint.sh \
  627. /etc/supervisord.conf
  628. USER ${USER_UID}:${USER_GID}
  629. ENV USER="${USER_NAME}" \
  630. HOME="/home/${USER_NAME}" \
  631. SHELL="/bin/bash"
  632. WORKDIR /home/${USER_NAME}
  633. EXPOSE 8080
  634. ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]