41

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?

1

8 Answers 8

33

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)

4
  • 2
    I've filled a feature request, but I doubt it will be implemented. Oh well.
    – Pier
    Aug 20, 2016 at 13:43
  • Oh, the agony -- in my case, I have 218 of them! (click menu, click delete, click delete... click menu, click delete, click delete... repeat 218 times...)
    – Venryx
    May 12, 2017 at 13:27
  • 6
    @Pier Please link to the feature request you created so we can track it. Thanks! Edit: I see feature requests on firebase are not public. Thats kind of...not great.
    – Levi
    May 22, 2017 at 18:39
  • @Levi It was also reported on the firebase-tools repo. To everyone: You can vote here (please avoid +1 spam, use reactions) github.com/firebase/firebase-tools/issues/… for one of the alternatives proposed by the team (batch delete, keep only X versions, keep versions with published date < Y)
    – nathan
    Nov 9, 2017 at 23:26
20

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)

4
  • I've made it to the last step, except I wanted to use the in-browser tools to send the DELETE requests. This seems to be correct: fetch(`https://firebasehosting.clients6.google.com/v1beta1/sites/${projectID}/versions/${versionID}?key=${key}`, {method: "DELETE", credentials: 'include'}); However, on running, it says "Request is missing required authentication credential." It's odd because the Network tab shows the requests as being identical. (other than tiny variations in two of the cookies, which seem unrelated)
    – Venryx
    Jan 16, 2018 at 15:33
  • @Venryx you figure that out? Feb 19, 2018 at 0:29
  • No, sorry. I ended up using @AAverin's solution above, which works fine.
    – Venryx
    Feb 20, 2018 at 1:56
  • Awesome. This should now be the answer. Oct 22, 2019 at 23:26
15

This script is not yet super-solid, so use it at your own risk. I'll try to update it later, but worked for me for now. Just some javascript to click on buttons to delete deployed items one by one.

var deleteDeployment = function(it) {
    it.click()
    setTimeout(function() {
        $('.md-dialog-container .delete-dialog button.md-raised:contains("Delete")').click()
    }, 300)
}
$('.h5g-hist-status-deployed').map((i, a) => $(a).parent()).map((i, a) => $(a).find('md-menu button:contains(Delete)')).each((i, it) => {
    setTimeout(function() {
        deleteDeployment(it)
    }, (i + 1) * 2000)
})
2
  • This cleared 3GB of old deployments in a matter of five minutes. Thank you! Jan 24, 2019 at 0:48
  • Cool! you make my life easier. Feb 26, 2019 at 14:13
5

Firebase finally implemented a solution for this.

It is now possible to set a limit of retained versions.

https://firebase.google.com/docs/hosting/deploying#set_limit_for_retained_versions

EDIT: previous link is outdated. Here is a new link that works:

https://firebase.google.com/docs/hosting/usage-quotas-pricing#control-storage-usage

2

This may be a bit brittle due to the selectors' reliance on current DOM structure and classes on the Hosting Dashboard, but it works for me!

NOTE: This script (if executed from the console) or bookmarklet will click and confirm delete on all of the rows in the current view. I'm fairly certain that even if you click delete on the current deployment it will not delete it.

Function for running in console:

let deleteAllHistory = () => {
  let deleteBtns = document.querySelectorAll('.table-row-actions button.md-icon-button');

  const deleteBtn = (pointer) => {
        deleteBtns[pointer].click();

        setTimeout(() => {
          document.querySelector('.md-open-menu-container.md-clickable md-menu-item:last-child button').click();

          setTimeout(() => {
            document.querySelector('.fb-dialog-actions .md-raised').click();

            if(pointer < deleteBtns.length - 1) {
              deleteBtn(pointer + 1);
            }
          }, 500);
        }, 500);
  };

  deleteBtn(0);
};

Bookmarklet:

javascript:(function()%7Bvar%20deleteBtns%3Ddocument.querySelectorAll('.table-row-actions%20button.md-icon-button')%2CdeleteBtn%3Dfunction(a)%7BdeleteBtns%5Ba%5D.click()%2CsetTimeout(function()%7Bdocument.querySelector('.md-open-menu-container.md-clickable%20md-menu-item%3Alast-child%20button').click()%2CsetTimeout(function()%7Bdocument.querySelector('.fb-dialog-actions%20.md-raised').click()%2Ca%3CdeleteBtns.length-1%26%26deleteBtn(a%2B1)%7D%2C500)%7D%2C500)%7D%3BdeleteBtn(0)%7D)()
1
  • beware this will delete the domain :| Apr 8, 2018 at 18:45
0

Nathan's option is great, but I have a quick-and-dirty method using AutoHotkey. Takes about a second per version to delete, so you can knock out a page in 10 seconds.

#a::
    Click
    MouseGetPos, xpos, ypos
    MouseMove, xpos, ypos + 30
    Sleep 300
    Click
    Sleep 400
    Click 1456, 816
    MouseMove, xpos, ypos + 82
return
#s::
    Click
    MouseGetPos, xpos, ypos
    MouseMove, xpos, ypos - 820
return

You'll likely need to modify the exact pixel values for your screen, but this works perfectly on my 1920x1080.

Win + a is delete and move to the next entry, Win + s is move to the next page. Put your mouse on the first 3-dot menu and go for it!

0

On top of the release history table, click the tool bar and select "Version history settings". Set to desired amount and click save.This will auto delete older deployments.

-1

I don't know it can help you or not but I can delete old deployments from "hosting" menu like this: Delete or rollback old deployment

2
  • 1
    You should put relevant code/instructions here in order to avoid any future broken link making you answer useless. Jun 29, 2017 at 7:03
  • 2
    Yes, but you have to do it manually. One by one. Did you even read the question?
    – Pier
    Jun 29, 2017 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.