0

How do I use Google Cloud Build with Yarn 2+? Do I need to create my own node image to support this or is there some shorthanded entrypoint like entrypoint: "yarn2"

Cloud Build with NodeJs:

steps:
  - name: "node"
    entrypoint: "yarn"

Currently results in:

Step #0: Pulling image: node
Step #0: Using default tag: latest
...
Step #0: yarn run v1.22.19
Maroben
  • 45
  • 7
  • Have you checked this [feature request](https://issuetracker.google.com/217593036) and [Github issue link](https://github.com/GoogleCloudPlatform/buildpacks/issues/175#issuecomment-1030519240) wherein it is suggested to use Yarn 2's PnP mode as Yarn 2 is not yet fully supported on Cloud Build? – Robert G Jan 19 '23 at 18:51
  • I see, I must have missed somewhere the information that Yarn2 is not supported yet officially. Would be nice if they included that in their Cloud Build docs. – Maroben Jan 28 '23 at 08:47

2 Answers2

1

Posting as a community wiki, as per previous comment, Yarn 2 is not yet fully supported on Google Cloud Build. It is suggested to use Yarn 2's PnP mode based on these documentation posted in Google Cloud feature request and Github issue link.

Robert G
  • 1,583
  • 3
  • 13
0

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
Augusto Franzoia
  • 570
  • 3
  • 13