Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean old deployed versions in Firebase hosting?

Every time you deploy to Firebase hosting a new deploy version is created so you can roll back and see who deployed. This means that each time every file you deploy is stored and occupying more space.

Other than manually deleting each deployed version one by one, is there any automated way to clean those useless files?

like image 854
Pier Avatar asked Aug 20 '16 01:08

Pier


People also ask

How do I remove deployment from Firebase?

Go to Firebase Console and select Hosting from the menu of the left. You will see the deployed project with a list of your historical actions like Deployed , disabled , etc. Only after you have disabled the site, the "three vertical dots" menu will be available for you to choose the action to delete the deployment.

How do I roll back Firebase deployment?

You can roll back a Firebase Hosting deployment from your project's Firebase Hosting page by selecting the Rollback action for the desired release. It's not currently possible to roll back releases of security rules for Firebase Realtime Database, Cloud Storage for Firebase, or Cloud Firestore.

How do you update a file that I deployed to Firebase Hosting?

You cannot change hosted files in the Firebase Console. Instead, you should change the index. html on your local copy where you initially ran the firebase deploy command. Once you're done with the changes, run firebase deploy again to push the updated version of your website to Firebase Hosting.


2 Answers

You're correct. You'll need to delete the old deployed versions one by one using the Firebase Hosting console.

There's no other way to do this, so I'd suggest you to file a feature request to enable deletion of multiple deployed version in the Firebase Hosting console.

Update:

You can vote here (please avoid +1 spam, use reactions) https://github.com/firebase/firebase-tools/issues/215#issuecomment-314211730 for one of the alternatives proposed by the team (batch delete, keep only X versions, keep versions with published date < Y)

like image 196
looptheloop88 Avatar answered Sep 18 '22 14:09

looptheloop88


UPDATE Mar/2019

There's now a proper solution: "Version history settings" which allows to keep the last X versions.

https://support.google.com/firebase/answer/9242086?hl=en


UPDATE Feb/2019

Confirmed by Google employee @ github.com/firebase/firebase-tools/issues/...

It is actively being worked on. ๐Ÿ™‚

๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰


Before continuing reading:

You can vote here (please avoid +1 spamming, use reactions) https://github.com/firebase/firebase-tools/issues/215#issuecomment-314211730 for one of the alternatives proposed by the team


So, by using Chrome Dev tools I found a way to delete multiple versions. Keep in mind it requires a bit for work (proceed with care since deleted versions can't be restored and you won't get any warnings like when using the UI).

Step 1. Retrieving the version list.

  1. Open Chrome Dev Tools (if you don't know how to chances are you should wait for a proper solution by Firebase's team).
  2. Open Firebase's Console and go to the "Hosting" tab.
  3. Go to the "Network" tab on CDT and use the Websockets filter.
  4. Select the request named .ws?v=5&ns=firebase
  5. Open the "Frames" tab
  6. Now comes the tedious part: Select the frames with the highest "length" value. (Depending on your data, it could be 2-n frames. In my case, 3 frames with 14k-16k length)
  7. Paste each of the frame's data in order (which will form a valid JSON object).
  8. Extracting the data: There are several ways to do it. I opted for simple JS on CDT's console.
    var jsonString = '...';     var json = JSON.parse(jsonString);     var ids = Object.keys(json.d.b.d); 

Step 2. Performing the requests

Almost there :P

Now that you have the IDs, perform the following requests:

DELETE https://firebasehosting.clients6.google.com/v1beta1/sites/PROJECT_NAME/versions/-VERSION_ID?key=KEY

I used Sublime (to create the request strings) + Paw.

The "KEY" can be copied from any of CDT's requests. It doesn't match Firebase's Web API key

=> Before performing the requests: take note of the version you don't want to delete from the table provided by Firebase. (Each version listed on the website has the last 6 digits of it's ID under your email)

(Screenshots weren't provided since all of them would require blurring and a bit of work)

like image 35
nathan Avatar answered Sep 22 '22 14:09

nathan