How to clean old deployed versions in Firebase hosting?

firebase hosting php
firebase hosting authentication
firebase hosting python
firebase hosting logs
firebase hosting sites
django firebase hosting
firebase hosting analytics
firebase hosting cache

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?

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)

List and delete deployments · Issue #215 · firebase/firebase-tools , I used old version firebase-tools. Update and deploy with index.js. But when I'm trying with my existing project after deploy process was done It said. Firebase Hosting Setup Complete You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary! So I'm pretty curious what I missing. here's package.json

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)
})

firebase deploy --remove functions or hosting · Issue #315 · firebase , string. Required. The name of the version to be deleted, in the format: sites/ site-​name /versions/ versionID https://www.googleapis.com/auth/firebase.hosting  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. For small changes it is probably faster to run firebase serve. This spins up a local web server, so that you can test the changes.

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)

Method: sites.versions.delete, Parameters and conditions · Templates and versioning · Config loading strategies Define your Firebase Hosting configuration in your firebase.json file. You can check the deployed firebase.json content using the Hosting REST API. When false , Hosting redirects URLs to remove a trailing slash. Updated the calculation for number of stored bytes, generally resulting in smaller amounts. New versions deployed to Hosting will use this new calculation. Versions that are already deployed will be updated during August. July 27, 2018 SDK Releases. The Firebase Android SDK for Cloud Firestore has been updated.

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)()

Configure hosting behavior, If you deploy code on any system and need a co-worker or client to see the most recent to be able to deploy code to firebase, and have users see the most recent version within a This is not tricky setup and uses old school web techniques. The Firebase CLI manages deployment of code and assets to your Firebase project, including: New releases of your Firebase Hosting sites. New, updated, or existing Cloud Functions for Firebase. Rules for Firebase Realtime Database. Rules for Cloud Storage for Firebase. Rules for Cloud Firestore.

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

Firebase Hosting Deployment Solution - Stephan Smith, Web Hosting. Website hosting and deployment with 99.95% guaranteed uptime. Cloud Storage for Firebase Deploy ready-to-go solutions in a few clicks. Why should you use Firebase Hosting? Firebase can be a good choice to deploy static websites, and Single Page Apps. I like to use Firebase Hosting mainly because I tested many different providers and Firebase offers an awesome speed across the continents without the need for a separate CDN on top, since the CDN is built-in for free.

Deleting deployments, You may sometimes want to remove an app from your Firebase project, such as removing an obsolete app variant. However, before deleting an app, you should​  If you run firebase init again and select Hosting, the command will overwrite the hosting section of the firebase.json file back to the default configuration. You can find a full firebase.json configuration example (covering only Firebase Hosting) at the bottom of this page.

Delete an app - Firebase Help, ✔️ The Solution — Delete All Old Deployments. After digging up some details about Firebase hosting and deployments, I found a very easy  I version my app in a couple of ways, including the version in package.json, and an notion of "builds", so I could also provide a version and/or build # to firebase deploy, and then if that could be listed in the list of deployed versions it would be fantastic. As it stands, I see 100 deployed versions and have no idea which is which.

How to Free Up Useless Space on Firebase Hosting for Your Static , Firebase can be a good choice to deploy static websites, and Single Page Apps. I like to use Firebase Now you choose which folder contains the static version of your site. A clean firebase.json file contains the following:. If you want to deploy and run existing functions built on Node.js 6, you must use a Firebase SDK for Cloud Functions lower than version 3.0.0 with Admin SDK lower than version 8.0.0. For deploying your functions, use Firebase CLI lower than 7.0.0.

Comments
  • This is now the answer as of March 2019: stackoverflow.com/a/47213789/1271706
  • I've filled a feature request, but I doubt it will be implemented. Oh well.
  • 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...)
  • @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 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)
  • This cleared 3GB of old deployments in a matter of five minutes. Thank you!
  • Cool! you make my life easier.
  • 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 you figure that out?
  • No, sorry. I ended up using @AAverin's solution above, which works fine.
  • Awesome. This should now be the answer.
  • beware this will delete the domain :|
  • You should put relevant code/instructions here in order to avoid any future broken link making you answer useless.
  • Yes, but you have to do it manually. One by one. Did you even read the question?