'npm run test'在服务器或我的本地服务器上完全可以正常运行,但是在我的docker机器上失败。我对这个docker世界有点陌生,所以我对这里出了什么问题感到困惑。 我收到错误消息:
Post stage
[32m15 07 2018 18:41:35.164:INFO [karma]: [39mKarma v1.2.0 server started at http://localhost:9876/
[32m15 07 2018 18:41:35.169:INFO [launcher]: [39mLaunching browser ChromeHeadless with unlimited concurrency
[32m15 07 2018 18:41:35.185:INFO [launcher]: [39mStarting browser ChromeHeadless
[31m15 07 2018 18:41:35.186:ERROR [launcher]: [39mNo binary for ChromeHeadless browser on your platform.
Please, set "CHROME_BIN" env variable.
Finished in 0 secs / 0 secs @ 18:41:35 GMT+0000 (UTC)
npm ERR! code ELIFECYCLE
我发现某处可能缺少chrome ..所以我在docker中手动安装了chrome:
# install manually all the missing libraries
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils
# install chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
然后我使用以下命令在docker内部设置chrome环境变量: 导出CHROME_BIN = / usr / bin / google-chrome
但是当我运行npm test时,它仍然失败并显示以下错误:
15 07 2018 19:20:46.291:INFO [launcher]: Starting browser ChromeHeadless 15% building modules 45/51 modules 6 active ...iv2/node_modules/zone.js/dist/zone.js15 07 2018 19:20:46.964:ERROR [launcher]: Cannot start ChromeHeadless
19% building modules 79/79 modules 0 active15 07 2018 19:20:47.750:INFO [launcher]: Trying to start ChromeHeadless again (1/2). 20% building modules 84/90 modules 6 active ...ode_modules/webpack/buildin/global.js15 07 2018 19:20:48.097:ERROR [launcher]: Cannot start ChromeHeadless
20% building modules 91/98 modules 7 active ...node_modules/angular2-moment/index.js15 07 2018 19:20:48.166:INFO [launcher]: Trying to start ChromeHeadless 22% building modules 103/156 modules 53 active ...s/rxjs/_esm5/operator/timeInterval.js15 07 2018 19:20:49.199:ERROR [launcher]: Cannot start ChromeHeadless
23% building modules 110/181 modules 71 active ...amic/esm5/platform-browser-dynamic.js15 07 2018 19:20:50.050:ERROR [launcher]: ChromeHeadless failed 2 times (cannot start). Giving up.
Finished in 0 secs / 0 secs @ 19:20:50 GMT+0000 (UTC)
23% building modules 111/185 modules 74 active ...e_modules/angular2-cookie/services.js
任何人都不知道我该如何解决。请注意,这是在我的docker内部发生的,我的基本docker映像是'python:2.7.13-slim'
答案 0 :(得分:1)
docker run命令通过-env-file
标志接受环境文件。
因此,您可以使用以下内容添加新的环境文件
CHROME_BIN=/usr/bin/google-chrome
并将此文件传递给docker run命令
docker run --env-file ./env.list -t -d ${BUILD_NAME}
请参考here以获取正式文档
这样,我们不只是为了设置env变量而伪造。
答案 1 :(得分:0)
答案 2 :(得分:0)
例如,使用angular/ngcontainer
的docker image而不是node。已经完成了用于测试UI应用程序的所有配置
Dockerfile
docker pull angular/ngcontainer
Jenkins CI
docker.image('angular/ngcontainer').inside {
npm run test
}
答案 3 :(得分:0)
根据发行版的不同,如果您的Debian实际基于/ opt / google / chrome / chrome,则chrome可能实际上位于其他地方
跑:
查找/ -name chrome -type f -perm / 111 -ls 2> / dev / null
它应该显示文件系统上实际可执行文件的位置