From 9b2556f49a2cac0decdc7299e238c4c0874fc687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Sun, 15 Dec 2024 17:22:52 +0100 Subject: [PATCH] More different base builds --- README.md | 10 ++++- alpine.Dockerfile | 66 +++++++++++++++++++++++++++++++++ apps/blender.Dockerfile | 2 +- apps/freecad.Dockerfile | 2 +- apps/musescore.Dockerfile | 2 +- apps/prusaslicer.Dockerfile | 6 +-- build.sh | 3 ++ debian.Dockerfile | 64 ++++++++++++++++++++++++++++++++ entrypoint.sh | 3 ++ novnc/webaudio.js | 1 + Dockerfile => ubuntu.Dockerfile | 47 +++++++++++------------ 11 files changed, 173 insertions(+), 33 deletions(-) create mode 100644 alpine.Dockerfile create mode 100755 build.sh create mode 100644 debian.Dockerfile rename Dockerfile => ubuntu.Dockerfile (73%) diff --git a/README.md b/README.md index 27adf42..c345ed3 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,14 @@ A desktop environment with sound in docker Can be used as a base file for application specific containers. +To just get a desktop environment at `http://localhost:8080`: + +```bash +docker run --rm thomasloven/novnc-base -p 8080:8080 +``` + +Or used as a base for specific applications: -E.g: ```dockerfile FROM thomasloven/novnc-base @@ -16,6 +22,8 @@ RUN sudo apt-get update \ CMD ["blender"] ``` +See more examples in `apps/`. + ### Bonus functionality - dotfiles installation. If the environment variable `DOTFILES_REPO` is set, the container will `git clone` that into `~/dotfiles` and then run `~/dotfiles/install.sh` if it diff --git a/alpine.Dockerfile b/alpine.Dockerfile new file mode 100644 index 0000000..2a6aaf7 --- /dev/null +++ b/alpine.Dockerfile @@ -0,0 +1,66 @@ +FROM alpine + +RUN apk update \ + && apk add \ +# Some basic helpers \ + bash \ + sudo \ + git \ + procps \ +\ +# X11 and XFCE \ + && apk add \ + xvfb xauth dbus-x11 xfce4 xfce4-terminal \ +\ +# VNC \ + && apk add \ + python3 py3-numpy \ + tigervnc \ + openssl \ +\ +# NoVNC \ + && mkdir -p /opt/noVNC \ + && git clone --single-branch https://github.com/novnc/noVNC.git /opt/noVNC \ + && git clone --single-branch https://github.com/novnc/websockify.git /opt/noVNC/utils/websockify \ + && ln -s /opt/noVNC/vnc.html /opt/noVNC/index.html \ + && openssl req -batch -new -x509 -days 365 -nodes -out self.pem -keyout /opt/noVNC/utils/websockify/self.pem \ +# Audio requirements \ + && apk add \ + pulseaudio \ + pavucontrol \ + ucspi-tcp6 \ + gstreamer \ + gstreamer-tools \ + gst-plugins-good \ + xfce4-pulseaudio-plugin + +COPY pulse/ /etc/pulse +COPY novnc /opt/noVNC/ +RUN sed -i "/import RFB/a \ + import '../webaudio.js'" \ + /opt/noVNC/app/ui.js + +# Base applications +RUN apk update \ + && apk add \ + firefox-esr neovim + +COPY entrypoint.sh /opt/noVNC/entrypoint.sh + +ENTRYPOINT ["/opt/noVNC/entrypoint.sh"] +EXPOSE 8080 + +RUN adduser --home /home/novnc --shell /bin/bash --system --disabled-password novnc \ + && echo "novnc ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +# Add a custom version of vncserver which discards all arguments but the display +RUN mv /usr/bin/vncserver /usr/bin/vncserver-orig \ + && echo -e "#!/bin/bash \n \ + /usr/bin/vncserver-orig \$1" > /usr/bin/vncserver \ + && chmod +x /usr/bin/vncserver + +USER novnc +RUN mkdir -p /home/novnc/.vnc/ \ + && echo -e "-Securitytypes=none" > /home/novnc/.vnc/config \ + && touch /home/novnc/.vnc/passwd && chmod 0600 /home/novnc/.vnc/passwd +WORKDIR /home/novnc diff --git a/apps/blender.Dockerfile b/apps/blender.Dockerfile index 20c4db2..72bb646 100644 --- a/apps/blender.Dockerfile +++ b/apps/blender.Dockerfile @@ -1,4 +1,4 @@ -FROM thomasloven/novnc-base +FROM thomasloven/novnc-ubuntu RUN sudo apt-get update \ && DEBIAN_FRONTEND=noninteractive \ diff --git a/apps/freecad.Dockerfile b/apps/freecad.Dockerfile index 5003070..6dc95f1 100644 --- a/apps/freecad.Dockerfile +++ b/apps/freecad.Dockerfile @@ -1,4 +1,4 @@ -FROM thomasloven/novnc-base +FROM thomasloven/novnc-ubuntu RUN sudo apt-get update \ && DEBIAN_FRONTEND=noninteractive \ diff --git a/apps/musescore.Dockerfile b/apps/musescore.Dockerfile index 0c1a1d1..bfd50d3 100644 --- a/apps/musescore.Dockerfile +++ b/apps/musescore.Dockerfile @@ -1,4 +1,4 @@ -FROM thomasloven/novnc-base +FROM thomasloven/novnc-ubuntu RUN sudo apt-get update \ && DEBIAN_FRONTEND=noninteractive \ diff --git a/apps/prusaslicer.Dockerfile b/apps/prusaslicer.Dockerfile index cd8d59d..8d2433a 100644 --- a/apps/prusaslicer.Dockerfile +++ b/apps/prusaslicer.Dockerfile @@ -1,12 +1,12 @@ -FROM thomasloven/novnc-base +FROM thomasloven/novnc-ubuntu -ARG APPIMAGE=PrusaSlicer-2.8.1+linux-x64-older-distros-GTK3-202409181354.AppImage +ARG APPIMAGE=PrusaSlicer-2.8.1+linux-x64-newer-distros-GTK3-202409181416.AppImage ARG URL=https://github.com/prusa3d/PrusaSlicer/releases/download/version_2.8.1/${APPIMAGE} RUN sudo apt-get update \ && DEBIAN_FRONTEND=noninteractive \ sudo apt-get install -y \ - libgtk-3-dev libglu1-mesa libwebkit2gtk-4.0-37 \ + libgtk-3-dev libglu1-mesa libwebkit2gtk-4.1-0 \ locales curl \ && sudo locale-gen en \ && curl -sSL ${URL} > ${APPIMAGE} \ diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..4bcca35 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +docker build $@ -t thomasloven/novnc-ubuntu -f ubuntu.Dockerfile . +docker build $@ -t thomasloven/novnc-debian -f debian.Dockerfile . +docker build $@ -t thomasloven/novnc-alpine -f alpine.Dockerfile . diff --git a/debian.Dockerfile b/debian.Dockerfile new file mode 100644 index 0000000..b0e213b --- /dev/null +++ b/debian.Dockerfile @@ -0,0 +1,64 @@ +FROM debian + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends\ +# Some basic helpers \ + bash \ + sudo \ + git \ + ca-certificates \ + procps \ +\ +# X11 and XFCE \ + && DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends\ + xvfb xauth dbus-x11 xfce4 xfce4-terminal \ + x11-xserver-utils \ +\ +# VNC \ + && DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends\ + python3 python3-numpy \ + tigervnc-standalone-server tigervnc-common \ + openssl \ +\ +# NoVNC \ + && mkdir -p /opt/noVNC \ + && git clone --single-branch https://github.com/novnc/noVNC.git /opt/noVNC \ + && git clone --single-branch https://github.com/novnc/websockify.git /opt/noVNC/utils/websockify \ + && ln -s /opt/noVNC/vnc.html /opt/noVNC/index.html \ + && openssl req -batch -new -x509 -days 365 -nodes -out self.pem -keyout /opt/noVNC/utils/websockify/self.pem \ + \ +# Audio requirements \ + && DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends\ + pulseaudio \ + pavucontrol \ + ucspi-tcp \ + gstreamer1.0-plugins-good \ + gstreamer1.0-pulseaudio \ + gstreamer1.0-tools + + +COPY pulse/ /etc/pulse +COPY novnc /opt/noVNC/ +RUN sed -i "/import RFB/a \ + import '../webaudio.js'" \ + /opt/noVNC/app/ui.js + +# Base applications +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends\ + firefox-esr neovim + +COPY entrypoint.sh /opt/noVNC/entrypoint.sh + +ENTRYPOINT ["/opt/noVNC/entrypoint.sh"] +EXPOSE 8080 + +RUN adduser --home /home/novnc --shell /bin/bash --system --disabled-password novnc \ + && echo "novnc ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers +USER novnc +WORKDIR /home/novnc diff --git a/entrypoint.sh b/entrypoint.sh index 8e9a84d..eb26a32 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,6 @@ #! /bin/bash + shopt -s nullglob kill_pid() { @@ -16,6 +17,7 @@ kill_pid ~/.pa-pid kill_pid ~/.tcp-pid kill_pid ~/.ws-pid + # Clone and install dotfiles if DOTFILES_REPO is defined if [ -n "$DOTFILES_REPO" ]; then if [ ! -d ~/dotfiles ]; then @@ -28,6 +30,7 @@ fi # Launch VNC server - view :1 defaults to port 5901 vncserver :1 -SecurityTypes None -localhost no --I-KNOW-THIS-IS-INSECURE & +# vncserver :1 & echo "$!" > ~/.vnc-pid # Launch pulseaudio server diff --git a/novnc/webaudio.js b/novnc/webaudio.js index a67703d..83481bc 100644 --- a/novnc/webaudio.js +++ b/novnc/webaudio.js @@ -134,6 +134,7 @@ const wa = new WebAudio(null); // Audio playback requires user interaction before being allowed by browsers const connect = () => { + if (MediaSource === undefined) return; if (!wa.connected) wa.start(); }; diff --git a/Dockerfile b/ubuntu.Dockerfile similarity index 73% rename from Dockerfile rename to ubuntu.Dockerfile index 8df4971..b358d61 100644 --- a/Dockerfile +++ b/ubuntu.Dockerfile @@ -3,42 +3,34 @@ FROM ubuntu RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive \ apt-get install -y --no-install-recommends\ +# Some basic helpers \ bash \ sudo \ git \ - procps - -RUN mkdir -p /opt/noVNC - -RUN adduser --home /home/novnc --shell /bin/bash --system --disabled-password novnc \ - && echo "novnc ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers - -# X11 and xfce -RUN apt-get update \ + ca-certificates \ + procps \ +\ +# X11 and XFCE \ && DEBIAN_FRONTEND=noninteractive \ apt-get install -y --no-install-recommends\ xvfb xauth dbus-x11 xfce4 xfce4-terminal \ - x11-xserver-utils - -# VNC -RUN apt-get update \ + x11-xserver-utils \ +\ +# VNC \ && DEBIAN_FRONTEND=noninteractive \ apt-get install -y --no-install-recommends\ - python3 python3-pip \ + python3 python3-numpy \ tigervnc-standalone-server tigervnc-common \ openssl \ - && pip3 install numpy - -# NoVNC -RUN git clone --single-branch https://github.com/novnc/noVNC.git /opt/noVNC \ +\ +# NoVNC \ + && mkdir -p /opt/noVNC \ + && git clone --single-branch https://github.com/novnc/noVNC.git /opt/noVNC \ && git clone --single-branch https://github.com/novnc/websockify.git /opt/noVNC/utils/websockify \ - && ln -s /opt/noVNC/vnc.html /opt/noVNC/index.html - -RUN openssl req -batch -new -x509 -days 365 -nodes -out self.pem -keyout /opt/noVNC/utils/websockify/self.pem - - -# Audio -RUN apt-get update \ + && ln -s /opt/noVNC/vnc.html /opt/noVNC/index.html \ + && openssl req -batch -new -x509 -days 365 -nodes -out self.pem -keyout /opt/noVNC/utils/websockify/self.pem \ + \ +# Audio requirements \ && DEBIAN_FRONTEND=noninteractive \ apt-get install -y --no-install-recommends\ pulseaudio \ @@ -48,13 +40,14 @@ RUN apt-get update \ gstreamer1.0-pulseaudio \ gstreamer1.0-tools + COPY pulse/ /etc/pulse COPY novnc /opt/noVNC/ RUN sed -i "/import RFB/a \ import '../webaudio.js'" \ /opt/noVNC/app/ui.js -# Extra applications +# Base applications RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive \ apt-get install -y --no-install-recommends\ @@ -65,5 +58,7 @@ COPY entrypoint.sh /opt/noVNC/entrypoint.sh ENTRYPOINT ["/opt/noVNC/entrypoint.sh"] EXPOSE 8080 +RUN adduser --home /home/novnc --shell /bin/bash --system --disabled-password novnc \ + && echo "novnc ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers USER novnc WORKDIR /home/novnc