Stop caching `node_modules` directory
Caching the node_modules
directory is inadvisable as the makeup is not always deterministic and incremental runs of yarn install
can have unexpected effects (especially when changing versions of yarn
).
This will also be problematic as subsequent builds containing different sets of dependencies will each overwrite their changes to the directory within the cache. A far better way to implement caching here is the way it is done in the main gitlab repo:
We cache a directory named .yarn-cache
:
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/.gitlab-ci.yml#L12
.default-cache: &default-cache
key: "ruby-2.4.4-debian-stretch-with-yarn"
paths:
- vendor/ruby
- .yarn-cache/
- vendor/gitaly-ruby
And we install our node modules using that directory to seed our yarn cache:
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/.gitlab-ci.yml#L415
compile-assets:
<<: *dedicated-runner
<<: *except-docs
<<: *use-pg
stage: prepare
cache:
<<: *default-cache
script:
- node --version
- date
- yarn install --frozen-lockfile --cache-folder .yarn-cache
...
Edited by Mike Greiling