镀铬在进行夜间测试时拒绝在M1上的Docker容器内部运行
我尝试运行一个之前在非 M1 平台上运行的 docker 映像,以使用 Chromedriver 和 chromium 运行 nightwatch 测试。当我切换到 M1 mac 时,测试的第一个断言将失败,这意味着 Chrome 甚至没有启动。我尝试了 Chromium 和 google-chrome-stable,两者都有同样的失败。我还尝试在 docker 容器内运行 VNC 服务器来查看发生了什么。当我进入并尝试启动 chrome 时,什么也没发生。当我尝试启动 Chromium 时,我收到一条消息,指出当前硬件不支持它。
这就是我构建 docker 容器的方式:
FROM node:10-buster-slim
WORKDIR /home/node
# Installing some missing but critical items:
# Chromium info: https://www.chromium.org/
RUN \
apt-get update && \
useradd apps && \
mkdir -p /home/apps && \
chown apps:apps /home/apps && \
apt-get install -y \
libglib2.0-0 \
libnss3 \
libx11-6 \
wget \
x11vnc \
xvfb \
fluxbox \
wmctrl \
gnupg2 && \
apt-get clean && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list && \
apt-get update && apt-get -y install google-chrome-stable
COPY docker-startup.sh /
RUN chmod 777 /docker-startup.sh
CMD '/docker-startup.sh'
# Copy only package.json and package-lock to start.
# Allows packages to to be cached in Docker layers, preventing the need to
# repeatedly re-install packages for any update to ui-tests.
COPY package.json package-lock.json ./
# Install testing dependencies (Nightwatch, Chromedriver)
# Use npm ci to install using package-lock.json, and not replace its contents.
# FYI: npm i chromedriver uses the version # from package.json
RUN \
npm ci && \
npm i -g [email protected] && \
npm i -g chromedriver@latest --unsafe-perm=true --allow-root
# Copies code over to the default working directory:
# The below COPY assumes you are copying /ui-tests to /ui-tests
COPY . .
# Sets variable used in Nightwatch Reporter:
ENV TEST_ENV=docker
ENV TERM=xterm-256color
# Resolves socket error / ECON reset
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null
有一个名为 docker-startup.sh 的 .sh 脚本,它只是设置并运行 VNC 服务器,以便我能够看看发生了什么,在这种情况下这并不是太重要。
用于运行 docker 容器的命令是这样的。
docker run --privileged -p 5900:5900 --user apps -e VNC_SERVER_PASSWORD=password --platform linux/amd64 -e APPBRANCH=$(git rev-parse --abbrev-ref HEAD) -v ~/work/dev/services/beast-portal/ui-tests/screenshots:/home/node/screenshots -v ~/work/dev/services/beast-portal/ui-tests/reports:/home/node/reports --env-file ./nightwatch.env nightwatch:stable nightwatch --env {--EnvironmentToTestIn--} --test {--TestToRun--.js}
它运行 docker 容器,然后使用给定的环境和给定的测试文件运行 nightwatch 测试。
用于构建 docker 文件的命令是这样的:
cd ~/work/dev/services/beast-portal/ui-tests && docker build --platform linux/amd64 -t \"nightwatch:stable\" .
我也尝试过弄乱 Chromedriver 和 nightwatch 的版本,但仍然给出相同的错误,它无法验证第一个断言,因为 chrome 甚至没有从它的外观启动。这感觉像是 M1 架构问题,但我无法弄清楚。
I have tried running a docker image, that previously worked on a non-M1 platform, to run nightwatch tests using Chromedriver and chromium. When I switched to an M1 mac, the first assertion of the test would fail, which implied that Chrome wasn't even starting up in the first place. I tried Chromium and google-chrome-stable, both of which had the same failure. I also tried running a VNC server inside of the docker container to see what is going on. When I got in and tried to start chrome, nothing happened. When I tried to start Chromium I got a message that it is not supported on the current hardware.
This is how I build my docker container :
FROM node:10-buster-slim
WORKDIR /home/node
# Installing some missing but critical items:
# Chromium info: https://www.chromium.org/
RUN \
apt-get update && \
useradd apps && \
mkdir -p /home/apps && \
chown apps:apps /home/apps && \
apt-get install -y \
libglib2.0-0 \
libnss3 \
libx11-6 \
wget \
x11vnc \
xvfb \
fluxbox \
wmctrl \
gnupg2 && \
apt-get clean && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list && \
apt-get update && apt-get -y install google-chrome-stable
COPY docker-startup.sh /
RUN chmod 777 /docker-startup.sh
CMD '/docker-startup.sh'
# Copy only package.json and package-lock to start.
# Allows packages to to be cached in Docker layers, preventing the need to
# repeatedly re-install packages for any update to ui-tests.
COPY package.json package-lock.json ./
# Install testing dependencies (Nightwatch, Chromedriver)
# Use npm ci to install using package-lock.json, and not replace its contents.
# FYI: npm i chromedriver uses the version # from package.json
RUN \
npm ci && \
npm i -g [email protected] && \
npm i -g chromedriver@latest --unsafe-perm=true --allow-root
# Copies code over to the default working directory:
# The below COPY assumes you are copying /ui-tests to /ui-tests
COPY . .
# Sets variable used in Nightwatch Reporter:
ENV TEST_ENV=docker
ENV TERM=xterm-256color
# Resolves socket error / ECON reset
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null
There is a .sh
script called docker-startup.sh
that just sets up and runs the VNC server for me to be able to see what is going on, that is not too important in this case.
The command used to run the docker container is this
docker run --privileged -p 5900:5900 --user apps -e VNC_SERVER_PASSWORD=password --platform linux/amd64 -e APPBRANCH=$(git rev-parse --abbrev-ref HEAD) -v ~/work/dev/services/beast-portal/ui-tests/screenshots:/home/node/screenshots -v ~/work/dev/services/beast-portal/ui-tests/reports:/home/node/reports --env-file ./nightwatch.env nightwatch:stable nightwatch --env {--EnvironmentToTestIn--} --test {--TestToRun--.js}
This runs the docker container and then runs the nightwatch test with a given environment and a given test file.
The command used to build the docker file is this :
cd ~/work/dev/services/beast-portal/ui-tests && docker build --platform linux/amd64 -t \"nightwatch:stable\" .
I have also tried messing with the versions of Chromedriver and nightwatch but that still gave the same error where it fails to verify the first assertion as chrome isn't even started from the looks of it. This feels like an M1 architecture issue but I can't figure it out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论