How do you run Gnome-Shell from inside Docker?
I'm trying to create a simple continuous build process for a Gnome Shell Extension, just to simulate and test installation. In order to make it easier to test the build for various flavors of Linux, I'd like to use Docker to manage the environment.
I'm first targeting Ubuntu 18.04, so I have a Dockerfile that looks like:
FROM ubuntu:18.04
ENV PYTHONUNBUFFERED 1
USER root
ENV HOME /home/root
# Setup localization.
ENV DEBIAN_FRONTEND noninteractive
RUN apt update
RUN apt install -y locales
RUN rm -rf /var/lib/apt/lists/* && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
RUN apt update
ENV LANG en_US.utf8
# Install dependencies
RUN apt-get -yq update && apt-get install -y gnupg2
RUN apt-key update
RUN apt-get -yq update
RUN apt-get -yq install xvfb gnome-shell git make bc dbus procps
RUN apt-get -yq purge whoopsie libwhoopsie*
# Install code.
RUN mkdir -p /home/root/git/my_extension
COPY . /home/root/git/my_extension
WORKDIR /home/root/git/my_extension
# Run test wrapper.
CMD ./docker_cmd_ubuntu1804.sh
And my docker_cmd_ubuntu1804.sh
script, which simulates launching the core background system daemons, installing the extension and then running some simple build tests looks like:
#!/bin/bash
set -e
echo "[$(date)] Launching Dbus."
mkdir -p /var/run/dbus
dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address
sleep 3 # give Dbus some time to start
echo "[$(date)] Launching Xvfb."
export DISPLAY=:99.0
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16
sleep 3 # give xvfb some time to start
echo "[$(date)] Launching Gnome-Shell."
sudo gnome-shell &
sleep 3 # give gnome-shell some time to start
echo "[$(date)] Confirming Gnome-Shell is running."
pgrep gnome-shell
echo "[$(date)] Showing Gnome-Shell log entries."
sudo journalctl /usr/bin/gnome-shell || true
echo "[$(date)] Rotating Gnome-Shell log entries."
sudo journalctl --rotate || true
echo "[$(date)] Clearing Gnome-Shell log entries."
sudo journalctl --vacuum-time=1s || true
echo "[$(date)] Show pre-extension Gnome-Shell performance."
ps -C gnome-shell -o %cpu,%mem,cmd || true
echo "[$(date)] Installing extension."
sudo make install
gnome-shell-extension-tool --enable-extension=my_extension
sleep 10 # Give extension time to run.
echo "[$(date)] Showing post-extension Gnome-Shell performance."
export MAX_CPU_PERCENT=20
export MAX_MEM_PERCENT=5
ps -C gnome-shell -o %cpu,%mem,cmd
# Check CPU. On localhost with 2.80GHz x 4 takes ~3%, on Travis ~15%.
bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %cpu|tail -1) < $MAX_CPU_PERCENT") -eq 1 ]]'
# Check memory. On localhost with 32GB of memory, ~0.6%, on Travis ~3%.
bash -c '[[ $(bc <<< "$(ps -C gnome-shell -o %mem|tail -1) < $MAX_MEM_PERCENT") -eq 1 ]]'
echo "[$(date)] Confirming extension hasn't thrown any errors."
# Note, finding no entries returns an error code of 1, which in our case means no error.
sudo journalctl --since=$(date '+%Y-%m-%d') /usr/bin/gnome-shell|grep -i "Extension \"my_extension\" had error"
Since the Ubuntu Docker image doesn't run a full desktop version of the OS, I'm simulating an X server with Xvfb. I then launch the main Gnome-Shell process, and this is where it's failing. It appears to be immediately crashing, and I'm not sure why.
The Gnome-Shell process outputs: "Window manager warning: Unsupported session type", but journalctl /usr/bin/gnome-shell
doesn't show anything useful.
How do I fix this?