如何从Docker内部运行Gnome-Shell
我正在尝试为Gnome Shell扩展创建一个简单的连续构建过程,只是为了模拟和测试安装。为了更容易地测试各种Linux版本的构建,我想使用Docker来管理环境。
我首先针对的是Ubuntu 18.04,所以我有一个Dockerfile,它看起来像:
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
我的docker_cmd_ubuntu1804.sh
脚本模拟启动核心后台系统守护进程,安装扩展,然后运行一些简单的构建测试,如下所示:
#!/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"
由于Ubuntu Docker镜像不能运行该操作系统的完整桌面版本,因此我使用Xvfb模拟X服务器。然后我启动主Gnome-Shell进程,这就是它失败的地方。它似乎马上就崩溃了,我不确定为什么。
Gnome-Shell进程输出:“窗口管理器警告:不支持的会话类型”,但是journalctl /usr/bin/gnome-shell
没有显示任何有用的内容。
我该如何解决这个问题?
发布于 2021-05-15 08:06:47
https://stackoverflow.com/questions/61194080
复制相似问题