【发布时间】:2020-12-16 17:11:41
【问题描述】:
'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'
【问题讨论】:
标签: node.js docker jenkins npm automated-tests