I want to create a global Yarn cache for my projects that are built on my CI servers. My projects are dockerized, and I have created a nightly job to populate this cache. Think of it as a project with a package.json
containing all dependencies from all projects. When this job is done, the cache is populated and I want this cache to be used by my daily jobs.
However, sometimes there are updates to these dependencies which are not cached before. Hence, Yarn tries to write to the cache directory. However, because of this issue and the corruption of cache in the case of multiple writers, I don't want to let my daily yarn install
s write to this pre-populated cache.
I currently have this in my Dockerfiles (using BuildKit):
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn/v6,ro yarn install
If I remove that ro
(readonly), I may face with a corrupted cache directory. If I keep it, my yarn install
may fail with something like this error when it needs to update its cache:
verbose 1.426 Error: EROFS: read-only file system, mkdir '/usr/local/share/.cache/yarn/v6/npm-bluebird-3.7.2-9f229c15be272454ffa973ace0dbee79a1b0c36f'
If I set the --cache-folder
to somewhere other than the populated cache, no cache is consumed.
Is there a way I can cache the packages this way? Docker layer caching is useless when the package.json
file is updated and causes the builds to take several minutes just to update a single muli-kilobytes dependency.