I have a NextJs app that uses an API hosted on Google Cloud Run during its static site generation (SSG). The SSG happens during the build step, which is performed inside a docker node.js container in Cloud Build. However, I get this error during the build:
Step #0: Error: Could not fetch ID token: Unsuccessful response status code. Request failed with status code 404
Step #0: at Gaxios._request (/app/node_modules/gaxios/build/src/gaxios.js:129:23)
Step #0: at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Step #0: at async metadataAccessor (/app/node_modules/gcp-metadata/build/src/index.js:68:21)
Step #0: at async Compute.fetchIdToken (/app/node_modules/google-auth-library/build/src/auth/computeclient.js:80:23)
Step #0: at async IdTokenClient.getRequestMetadataAsync (/app/node_modules/google-auth-library/build/src/auth/idtokenclient.js:35:29)
Step #0: at async IdTokenClient.getRequestHeaders (/app/node_modules/google-auth-library/build/src/auth/oauth2client.js:247:26)
...
This happens when trying to fetch an ID token with the google-auth-library
like so:
await this.googleAuth.getIdTokenClient(...)
The build command running the build (the -t
parameter is passed the image name and version, I just omitted it here):
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '--network=cloudbuild', '-t', '...', '.']
The 404 error indicates that Cloud Build can't find whatever service is used to get an ID token. I have found some similar errors:
- Google Cloud Build fetch Identity token -> This workaround would be a bit of a hassle to implement for us. I'm hoping to avoid it.
Is there any way to allow google-auth-library
to fetch an ID token inside Cloud Build?