I've deployed hundreds of function and this is the first time I encounter this issue. Simply, it stops deploying function process, saying:
Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually at https://console.cloud.google.com/gcr/images/[project-name]/us/gcf
The way I deploy is through Firebase CLI command: firebase deploy --only functions:nameOfFunction
Question is what are those images I have to delete? Why? How can I solve it?
Cloud Functions uses another product called Cloud Build to build the server images that actually get deployed. Those images are stored in Cloud Storage, and that storage is billed to your account.
Read more about it:
https://github.com/firebase/firebase-tools/issues/3404
https://krasimirtsonev.com/blog/article/firebase-gcp-saving-money
Watch:
https://www.youtube.com/watch?v=aHaI0jZ5rwM
You should be able to locate and delete the files manually in the Google Cloud console. But it sounds like there is a bug here with the files not being cleaned up automatically, so you contact Firebase support directly.
For me the issue appeared to be related to my GCF billing (https://console.cloud.google.com/billing)
I had to go to my billing account to see that my payment method was expired or something, and GCF had forecasted a monthly cost of $0.01, so deploying cloud functions was sort of locked until I updated the payment method. Then the deploy immediately worked again after updating it. The build-cleanup console warning also disappeared.
The error I was seeing in my function logs in firebase console was "billing account is not available". Which I found almost zero results for in Google. Which is why I'm posting it here.
For me, the issue was caused by a silly typo.
The error:
Functions deploy had errors with the following functions:
sendNotification(europe-west) i functions: cleaning up build files... ⚠ functions: Unhandled error cleaning up build images. This
could result in a small monthly bill if not corrected. You can attempt
to delete these images by redeploying or you can delete them manually
at...
The fix was choosing the right region.
The incorrect region:
exports.sendNotification = functions
.region("europe-west")...
The correct region:
exports.sendNotification = functions
.region("europe-west3")...
Go to https://console.cloud.google.com/apis/api/artifactregistry.googleapis.com/overview
select your project
enable Artifact Registry API
deploy functions again
In my experience going into Cloud Storage didn't solve the issue: there was no image there to be deleted.
I solved by changing the Node version, moving from 18 to 14.0.0
nvm install 14.0.0
nvm use 14.0.0
Check your Function logs, by either navigating through functions in the Firebase console or through https://console.cloud.google.com/logs
For me, the logs indicated that one of my typescript files had compiled under the wrong name and it was messing up the build.
Check the logs!
General troubleshooting tips given the variety of answers here:
if build is failing, read for other errors further up in the build output
add --debug to your CLI call, i.e.:
firebase deploy --only functions --debug
With --debug I found this in my output: "Permission 'artifactregistry.packages.delete' denied on resource"
My solution was to add Artifact Registry Administrator role to the IAM user deploying the function (in addition to Firebase Admin & Service Account User roles).
When I run the command "firebase deploy --only functions" it takes around 1 minute to deploy my function even if I didn't update my function.
Am I doing something wrong?
Could it be because of the node_modules folder in my functions folder?
Is function deployment in firebase just slow?
Console Log:
C:\Users\myUser\Desktop\myProject> firebase deploy --only functions
=== Deploying to 'myProject'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (36.96 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: updating Node.js 10 (Beta) function myFunction(europe-west1)...
i scheduler: ensuring necessary APIs are enabled...
i pubsub: ensuring necessary APIs are enabled...
+ scheduler: all necessary APIs are enabled
+ pubsub: all necessary APIs are enabled
i functions: scheduler job firebase-schedule-myFunction-europe-west1 is up to date, no changes required
+ functions[myFunction(europe-west1)]: Successful update operation.
+ Deploy complete!
It usually gets stuck for 1 minute on this line:
i functions: scheduler job firebase-schedule-svt-europe-west1 is up to date, no changes required
1-2 minutes is typical. Unlike some other FaaS providers, Cloud Functions is actually running npm install and building the node_modules in the cloud, which does take some time but also means you don't need to worry about cross-compiling native dependencies.
Cloud Functions doesn't know if you updated your function or not, so it does a fresh redeploy every time.
My recommendation is to ONLY update the functions you changed. You can do this with the following:
firebase deploy --only functions:specificFunctionName,functions:anotherFunctionName,etc
This should speed things up at least a little bit, but probably not a lot.
When I try to run `Firebase deploy', it stucks at this line of code
i deploying functions
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
the firebase init and firebase login are doing fine but firebase deploy keeps stuck. My firebase version is 3.18.4 and im currently using ubuntu 17.10.
EDIT:
and after waiting for about an hour it diplays this line of code
FIREBASE WARNING: auth() was canceled: Auth token is expired.
Am I doing something wrong?. I am new to Firebase and I need some tips/ advice on why this happening
Here is a tip, that might help you. Give it a try and tell me if it resolves your issue.
Always use these commands instead of just firebase deploy
firebase deploy --only hosting
firebase deploy --only functions <<- use this in ur case. Also make sure your in the directory /functions of your project where you ran your firebase init
Sometimes Firebase services may be down, which would prevent you from deploying your code. If you can't deploy, check this site and see if at least all services are up and running: https://status.firebase.google.com/
I seem to be having issues getting my site live onto the Firebase Hosting.
I followed this tutorial: https://github.com/firebase/functions-samples/tree/master/stripe
Which has these steps:
Create a Firebase Project using the Firebase Developer Console
Enable billing on your project by switching to the Blaze or Flame plan. See pricing for more details. This is required to be able to do requests to non-Google services.
Enable Google sign on your Firebase project
Install Firebase CLI Tools if you have not already and log in with firebase login.
RESULT: Already logged in as user#gmail.com
Configure this sample to use your project using firebase use --add and select your project.
RESULT: Error: Firebase use must be run from a Firebase Directory
Run firebase init to start a project
Run firebase init
What Firebase CLI features do you want to setup for this directory?
Database
Functions
Hosting
I chose HOSTING.
Select a default Firebase project for this directory
I Chose the only project there and got:
✔ Firebase initialization complete
I Ran Firebase use --add again, chose and alias and not it says:
Now using alias stageTemp.
Install dependencies locally by running: cd functions; npm install; cd -
npm WARN stripe-functions# No repository field
npm WARN stripe-functions# No license field.
Add your Stripe API Secret Key to firebase config: firebase functions:config:set stripe.token=<YOUR STRIPE API KEY>
Optional: change your default currency firebase functions:config:set stripe.currency=GBP
Pass your Stripe publishable key to the Stripe.setPublishableKey call in public/index.html
Deploy your project using firebase deploy
When I run Firebase Deploy I get
i deploying functions
i functions: ensuring necessary APIs are enabled...
i runtimeconfig: ensuring necessary APIs are enabled...
✔ runtimeconfig: all necessary APIs are enabled
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (2.91 KB) for uploading
✔ functions: functions folder uploaded successfully
i starting release process (may take several minutes)...
i functions: updating function createStripeCharge...
i functions: updating function createStripeCustomer...
i functions: updating function addPaymentSource...
i functions: updating function cleanupUser...
✔ functions[createStripeCharge]: Successful update operation.
✔ functions[createStripeCustomer]: Successful update operation.
✔ functions[addPaymentSource]: Successful update operation.
✔ functions[cleanupUser]: Successful update operation.
✔ functions: all functions deployed successfully!
✔ Deploy complete!
Finally:
Test your Stripe integration by viewing your deployed site firebase open hosting:site
and then I get this:
Can anyone see why this is not working? I have gone through these steps several times and cannot seem to get it to work.
Much appreciated.
Questions for Firebase Devs:
1) This code on the example has: amount: parseInt(). What checks are in place to make sure that the DOM is not simply edited by the user?
2) This process saves a lot of data. Is Firebase PCI Compliant so that I am legally allowed to store this data?
3) I'm confused about the process flow of functions. Is there an editable file that is run on the cloud where I can add extra information and database interactions or email sending? - I ask this because I want to insert into the database only when payment is verified. If I code it from the front end then a user could just run that in the console or wherever and insert into my db as it will have write access. (I hope this makes sense - I basically just want my function to be able to access the database and not anyone else)
Thank you for your time, I understand that you will be terrible busy and I really appreciate your help with this.
After a month of successful deploying the functions deploy of new functions to Firebase database started to fail. The process halts at the point functions: preparing functions directory for uploading... and eventually stops when token expires. Running deploy with --debug flag does not give more info. I tried both deploying new code and reusing old functions on new DB nodes.
Could someone please give me a hint on what happens on this stage of deploy?
Is there a limit for the number of deployed functions I missed?
Upd: Problem solved by updating firebase-tools from 3.5.0 to 3.7.0