【发布时间】:2020-12-08 14:00:31
【问题描述】:
情况是这样的: 我在 Gitlab CI(由 vue-cli 启动)中运行赛普拉斯测试。为了加快执行速度,我构建了一个包含必要依赖项的 Docker 映像。 如何从预建映像缓存 node_modules 以在测试作业中使用它? 目前我正在使用一个糟糕(但有效)的解决方案:
testsE2e:
image: path/to/prebuiltImg
stage: tests
script:
- ln -s /node_modules/ /builds/path/to/prebuiltImg/node_modules
- yarn test:e2e
- yarn test:e2e:report
但我认为使用 Gitlab CI 缓存必须有一种更清洁的方式。
我一直在测试:
cacheE2eDeps:
image: path/to/prebuiltImg
stage: dependencies
cache:
key: e2eDeps
paths:
- node_modules/
script:
- find / -name node_modules # check that node_modules files are there
- echo "Caching e2e test dependencies"
testsE2e:
image: path/to/prebuiltImg
stage: tests
cache:
key: e2eDeps
script:
- yarn test:e2e
- yarn test:e2e:report
但作业 cacheE2eDeps 显示 "WARNING: node_modules/: no matching files" 错误。
我怎样才能成功地做到这一点? Gitlab 文档并没有真正谈论从预建图像中缓存...
用于构建镜像的 Dockerfile :
FROM cypress/browsers:node13.8.0-chrome81-ff75
COPY . .
RUN yarn install
【问题讨论】:
标签: node-modules gitlab-ci cypress