互联网上充斥着关于Gitlab没有缓存的抱怨,但在我的情况下,我认为,Gitlab CI确实可以正确缓存。问题是,无论如何,npm似乎再安装所有东西。
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- vendor/
- bootstrap/
- node_modules/
build-dependencies:
image: ...
stage: build
script:
- cp .env.gitlab-testing .env
- composer install --no-progress --no-interaction
- php artisan key:generate
- npm install
- npm run prod
- npm run prod
artifacts:
paths:
- vendor/
- bootstrap/
- node_modules/
- .env
- public/mix-manifest.json
tags:
- docker
这是我的gitlab-ci.yml文件(嗯......相关部分)。虽然使用了缓存的composer依赖项,但node_modules却没有。我甚至在绝望中添加了缓存和工件的所有内容。
实际上它应该工作,你的缓存是全局设置,你的密钥是指当前分支${CI_COMMIT_REF_SLUG}
...
这是我的构建,似乎在各阶段之间缓存node_modules。
image: node:latest
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
- .next/
stages:
- install
- test
- build
- deploy
install_dependencies:
stage: install
script:
- npm install
test:
stage: test
script:
- npm run test
build:
stage: build
script:
- npm run build