小编Jou*_*lss的帖子

Gitlab CI:如何从预构建的映像中缓存 node_modules?

情况是这样的:我在 Gitlab CI(由 vue-cli 启动)中运行 Cypress 测试。为了加快执行速度,我构建了一个包含必要依赖项的 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
Run Code Online (Sandbox Code Playgroud)

但我认为使用 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
Run Code Online (Sandbox Code Playgroud)

但作业 cacheE2eDeps …

node-modules gitlab-ci cypress

1
推荐指数
1
解决办法
1956
查看次数

标签 统计

cypress ×1

gitlab-ci ×1

node-modules ×1