I'm trying to cache my node_module dependencies to speed up my build time, but the zip file that results is empty. With inspiration from THIS response to another question I have the following cloudbuild.yaml.
steps:
- id: 'download-cached-yarn-dependencies'
name: gcr.io/cloud-builders/gsutil
entrypoint: bash
args:
- '-c'
- |
gsutil cp gs://${PROJECT_ID}_cloudbuild/my-app.cache.tgz build-cache.tgz || exit 0
tar -zxf build-cache.tgz || exit 0
- id: install
name: $_NODE
entrypoint: 'bash'
args:
- '-c'
- |
mkdir .yarn-cache
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 -zcvf build-cache.tgz .yarn-cache
gsutil cp build-cache.tgz gs://${PROJECT_ID}_cloudbuild/my-app.cache.tgz
The only thing that I modified from the previous ANSWER was to add mkdir .yarn-cache to avoid a "Cannot stat: No such file or directory" error.
This build successfully created a my-app.cache.tgz file in my storage bucket, but when unzipped, it is empty.
I also tried to remove the line yarn config set globalFolder .yarn-cache and use the default cache folder /usr/local/share/.config/yarn/global (SOURCE) but this also gave a "Cannot stat: No such file or directory" error.
How can I successfully zip the global folder for reuse in later builds?
I've modified my approach based on THIS answer to another question.