如何dockerize一个NX cypress e2e应用程序



我有一个NX工作区,只包含一个angular应用程序和它的e2e应用程序,这是使用cypress

我正在尝试为端到端测试创建一个docker映像,但是当我运行docker容器时失败了。这是我的Dockerfile,它现在位于工作空间的根文件夹中。

FROM node:lts-alpine
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
COPY decorate-angular-cli.js /app/decorate-angular-cli.js
RUN npm install
RUN npm install -g @angular/cli@latest
RUN npm install reflect-metadata tslib
# add cypress dependencies for image build 
RUN apk add xauth xvfb
# add app
COPY . /app
CMD npm run e2e -- --headless

映像已构建,但当我运行容器时,我得到柏树依赖错误。

✔ Browser application bundle generation complete.
Initial Chunk Files | Names         |      Size
vendor.js           | vendor        |  11.33 MB
styles.css          | styles        | 685.68 kB
polyfills.js        | polyfills     | 128.53 kB
main.js             | main          | 118.15 kB
runtime.js          | runtime       |   6.61 kB
| Initial Total |  12.25 MB
Build at: 2021-09-20T15:27:50.264Z - Hash: 8cbcb444b6a50b421afd - Time: 86112ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

✔ Compiled successfully.
It looks like this is your first time using Cypress: 7.7.0
[STARTED] Task without title.
[FAILED] Cypress failed to start.
[FAILED]
[FAILED] This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies
[FAILED]
[FAILED] Please refer to the error below for more details.
[FAILED]
[FAILED] ----------
[FAILED]
[FAILED] Command failed with ENOENT: /root/.cache/Cypress/7.7.0/Cypress/Cypress --no-sandbox --smoke-test --ping=690
[FAILED] spawn /root/.cache/Cypress/7.7.0/Cypress/Cypress ENOENT
[FAILED]
[FAILED] ----------
[FAILED]
[FAILED] Platform: linux (Alpine Linux - 3.11.12)
[FAILED] Cypress Version: 7.7.0
Cypress failed to start.
This may be due to a missing library or dependency. https://on.cypress.io/required-dependencies
Please refer to the error below for more details.
----------
Command failed with ENOENT: /root/.cache/Cypress/7.7.0/Cypress/Cypress --no-sandbox --smoke-test --ping=690
spawn /root/.cache/Cypress/7.7.0/Cypress/Cypress ENOENT
----------
Platform: linux (Alpine Linux - 3.11.12)
Cypress Version: 7.7.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! icert@2.0.0 e2e: `ng e2e "--headless"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the icert@2.0.0 e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-09-20T15_27_51_378Z-debug.log

我需要知道这是否是用Nxdockerizing e2e apps的正确方法,如果是的话,那么我在这里错过了什么。

谢谢!

问题是Alpine Linux还不支持Cypress(或者可能永远不支持)。我建议您使用官方支持的Cypress Docker映像之一。即使你设法让Cypress在Alpine上运行,它也需要下载大量的外部依赖来构建Chrome/Electron,这将使磁盘大小优化可以忽略不计。

相关内容

最新更新