DEV Community

Cover image for Firebase Hosting Version Settings
Alex Patterson for CodingCatDev

Posted on • Originally published at codingcat.dev

Firebase Hosting Version Settings

If you start to get that feeling like "Why am I getting billed for this tiny app" from Firebase, then this blog is for you!

Dashboard

If you project is currently using hosting, you should see your dashboard as soon as you enter your project. You can either click on your last deployment history or go to Hosting in the menu.

Hosting Usage

You may see multiple sites that you are currently hosting in this screen. For now lets switch over to the Usage tab. You should see a chart listed year of you trending stored bytes. In my graphy this shows a recent trendline upward (as I have been deploying a lot).

If this type of storage trend where to continue I would eventually break into the 1GB limit for storage on this site, now granted for my 5MB it would take a great deal of time.

Updating Version

If you have multiple domains select View on the one that you want to change. Once you are in the Manage site area, you will see all of your domains at the top then the release history at the bottom.

It is in the Release History section that you will be able to select Version history settings, from the hamburger menu.

When you get the modal screen to change the versions, you will see based on your selection the estimated storage. If you have several (in my case 100's) of versions stored you will notice that a background job is kicked off that will mark your old versions for deletion.

Once the delete action has finished you will notice that your older deployments will have an Auto deleted indicator.

REST Service

You can also automate this process if you are not into the Admin GUI through the Firebase Hosting API.

Shell script

#!/bin/bash set -eo pipefail echo "Deleting existing hosting releases" SITE=$1 echo "Site: $SITE" HEADER_AUTH="Authorization: Bearer "$(gcloud auth application-default print-access-token)""; PAGE_TOKEN= FIRST=true while : do echo "Fetching releases for $PAGE_TOKEN" RELEASES=$( \ curl \ -sS \ -H "$HEADER_AUTH" \ "https://firebasehosting.googleapis.com/v1beta1/sites/$SITE/releases?pageToken=$PAGE_TOKEN&pageSize=25" \ ) for RELEASE_ID in $(echo $RELEASES | jq '.releases | keys[]') do VERSION_NAME=$(echo $RELEASES | jq --raw-output ".releases[$RELEASE_ID].version.name") MESSAGE=$(echo $RELEASES | jq --raw-output ".releases[$RELEASE_ID].message") VERSION_STATUS=$(echo $RELEASES | jq --raw-output ".releases[$RELEASE_ID].version.status") if [ "$VERSION_STATUS" == "FINALIZED" ] && [ "$FIRST" == false ] then echo "Deleting release $MESSAGE ($VERSION_NAME)"; curl \ -sS \ -X DELETE \ -H "$HEADER_AUTH" \ "https://firebasehosting.googleapis.com/v1beta1/$VERSION_NAME" fi FIRST=false done if [ $(echo $RELEASES | jq --raw-output '.nextPageToken') == "null" ] then exit 0 fi PAGE_TOKEN=$(echo $RELEASES | jq --raw-output '.nextPageToken') sleep 1s done
Enter fullscreen mode Exit fullscreen mode

Top comments (0)