How to clean old deployed versions in Firebase hosting?
Solution 1
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
Solution 2
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)
Solution 3
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.
- Open Chrome Dev Tools (if you don't know how to chances are you should wait for a proper solution by Firebase's team).
- Open Firebase's Console and go to the "Hosting" tab.
- Go to the "Network" tab on CDT and use the Websockets filter.
- Select the request named
.ws?v=5&ns=firebase
- Open the "Frames" tab
- 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)
- Paste each of the frame's data in order (which will form a valid JSON object).
- 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)
Solution 4
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)
})
Solution 5
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)()
![Pier](https://i.stack.imgur.com/R2WQD.png?s=256&g=1)
Pier
Updated on June 08, 2022Comments
-
Pier about 2 years
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?
-
Pier almost 8 yearsI've filled a feature request, but I doubt it will be implemented. Oh well.
-
Venryx about 7 yearsOh, 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...)
-
Levi about 7 years@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.
-
Benoît Latinier almost 7 yearsYou should put relevant code/instructions here in order to avoid any future broken link making you answer useless.
-
Pier almost 7 yearsYes, but you have to do it manually. One by one. Did you even read the question?
-
nathan over 6 years@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)
-
Venryx over 6 yearsI'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) -
Joshua Kifer over 6 years@Venryx you figure that out?
-
Venryx over 6 yearsNo, sorry. I ended up using @AAverin's solution above, which works fine.
-
KhaledMohamedP about 6 yearsbeware this will delete the domain :|
-
eat-sleep-code over 5 yearsThis cleared 3GB of old deployments in a matter of five minutes. Thank you!
-
Mihae Kheel over 5 yearsCool! you make my life easier.
-
Dylan Watson over 4 yearsAwesome. This should now be the answer.