I am using Cloud Storage to store Yarn v2 cache in a compressed file. I switched from using --cache-from
functionality from Cloud Build to this method and the build time has decreased from ~3 min to ~1.5min
steps:
- id: 'download-cached-yarn-dependencies'
name: gcr.io/cloud-builders/gsutil
entrypoint: bash
args:
- '-c'
- |
gsutil cp gs://my-cache-bucket/my-app.cache.tgz build-cache.tgz || exit 0
tar -zxf build-cache.tgz || exit 0
- id: 'install-dependencies'
name: node:16
entrypoint: bash
args:
- '-c'
- |
yarn config set enableGlobalCache true
yarn config set globalFolder .yarn-cache
yarn install --immutable
- id: 'upload-cached-yarn-dependencies'
name: gcr.io/cloud-builders/gsutil
entrypoint: bash
args:
- '-c'
- |
tar -zcf build-cache.tgz .yarn-cache
gsutil cp build-cache.tgz gs://my-cache-bucket/my-app.cache.tgz