Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete outdated Firebase Cloud function containers from GC Storage?

So recently Firebase started charging for Cloud Functions container storage: https://firebase.google.com/pricing

No free usage $0.026/GB

I have deployed 2 functions several times (no more than 10 times, can't remember exact count, but this is still pretty low, IMO). Now I am already billed a small amount (fractions of a cent for now). So seems that if I deploy the functions another few dozens of times, I'll get close to a dollar, because old (and unused) containers are not deleted from the storage bucket.

Is there a way to safely delete outdated, not used containers to free some space? Well, it may seem that a few cents are not worth the time, but still, that's not what a free tier should be like.

like image 225
ololoepepe Avatar asked Sep 14 '20 12:09

ololoepepe


People also ask

How do I remove a function from Firebase?

You can delete previously deployed functions in these ways: explicitly in the Firebase CLI with functions:delete. explicitly in the Google Cloud Console. implictly by removing the function from index.

How do you delete firebase logs?

There's currently no way to delete logs from the Firebase Console. @TheeBen the same reason you may want to delete or archive read emails in your inbox. during development, deleting irrelevant logs is very important.


3 Answers

I found the only robust solution to this ongoing issue (for now) is to periodically remove all of the artifact files (following Doug's instructions). As noted by others, removing some of the files can cause subsequent deploy errors (I experienced these).

IMPORTANT: Only delete the artifact files, NOT the folders as this can also cause issues.

You can do partial or full deploys as normal without any issues (it seems that the artifact files are only referenced during the build/deploy process).

Not ideal by a long shot, but at least reduces the storage usage to the minimum (until it starts accumulating again).

Edit: I have experimented with Lifecycle rules in the artifacts bucket to try and automate the clearing out of the container, but the parameters provided cannot guarantee that ALL will be cleared in one hit (which you need it to).

For convenience, you can see the artifacts bucket from within the Firebase Storage UI by selecting the "Add Bucket" option and importing the buckets from GCP.

like image 198
D G Avatar answered Sep 21 '22 09:09

D G


  1. Go to the Cloud console
  2. Select "Cloud Storage -> Browser" from the products in the hamburger menu.
  3. You will see multiple storage buckets there. Simply dig in to the buckets that start with "artifacts" or end with "cloudbuild" and delete the old files (by date) that you don't want.
like image 36
Doug Stevenson Avatar answered Sep 22 '22 09:09

Doug Stevenson


In case of Firebase Cloud Functions you can see from their documentation (lifecycle of a background function section):

When you update the function by deploying updated code, instances for older versions are cleaned up along with build artifacts in Cloud Storage and Container Registry, and replaced by new instances.

When you delete the function, all instances and zip archives are cleaned up, along with related build artifacts in Cloud Storage and Container Registry. The connection between the function and the event provider is removed.

It means that there is no need to manually cleanup and firebase deploy scripts are doing it automatically.

You should not remove build artifacts since cloud functions are scaling automatically and new instances are built from theese artifacts.

I don't really think that cost is nearly a problem since it's 0.026$/GB so you need very approximately about 76 functions to pay 1$ for their artifacts storage (I take approx size of 1 function's artifacts as 500mb). Also artifacts size should not grow up with every functions since it's basically size of dependencies which are more or less independent from number of deployed functions.

like image 39
Georgii Avatar answered Sep 20 '22 09:09

Georgii