Firebase deploy functions with Sharp library fails in Google Cloud Build

天涯浪子 提交于 2020-03-03 12:24:59

问题


After migrating to Google Cloud Build from Bitbucket Pipelines the Firebase deployment is failing. The setup was deploying successfully both on Bitbucket Pipelines and locally.

No further explanation is given other than error below. I have comment parts of the code to to realize that "const sharp = require('sharp')" was one command that was making the build to fail.

But there is no apparent reason why "firebase deploy" fails with "require('sharp')" and I have to way to tackle this.

Firebase deploy output in Google Cloud Build

Step #5: === Deploying to 'werkout-staging-b1483'...
Step #5: 
Step #5: i  deploying functions
Step #5: ✔  functions: Finished running predeploy script.
Step #5: i  functions: ensuring necessary APIs are enabled...
Step #5: ✔  functions: all necessary APIs are enabled
Step #5: i  functions: preparing functions/cloud_functions directory for uploading...
Step #5: 
Step #5: Error: There was an unknown problem while trying to parse function triggers. Please ensure you are using Node.js v6 or greater.
Finished Step #5
ERROR
ERROR: build step 5 "gcr.io/werkout-staging-b1483/firebase" failed: exit status 2

Dockerfile

FROM cypress/base:10.15.3

#CMD ["node"]

RUN npm install -g firebase-tools@^7.0.0
ENTRYPOINT ["/usr/local/bin/firebase"]

Any ideas?


回答1:


I figure it out for real this time.

I ran npm ci to build the cloud functions and them firebase deploy to deploy them to the cloud. The problem was that as you see in the docker file above gcr.io/$PROJECT_ID/firebase image was build with node 10.15.3 while the gcr.io/cloud-builders/npm was using node 8. The only npm packages that was picky enough was Sharp and so it failed to build.

Worst of all is that firebase was very secretive about this and I have no lead to tackle over than pure speculation.

- name: 'gcr.io/cloud-builders/npm'
  args: [ 'run', 'build' ]

- name: 'gcr.io/$PROJECT_ID/firebase'
  args: [ 'firebase', 'deploy' ]

The solution:

- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
  args: [ 'run', 'build' ]

- name: 'gcr.io/$PROJECT_ID/firebase'
  args: [ 'firebase', 'deploy' ]

And this should match the version of the node engine specified in cloud functions package.json.



来源:https://stackoverflow.com/questions/56675535/firebase-deploy-functions-with-sharp-library-fails-in-google-cloud-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!