CLI tool
The Firebase CLI tool enables several workflows:
- Emulate the Firebase backend locally, to run it and debug it at no cost.
- Scaffold the Cloud Functions' directory, and deploy Cloud Functions.
- Submit secrets or API keys to Google, to make them available in Cloud Functions.
- Add and deploy security rules.
- List the Firebase projects linked to the Google account.
the CLI executable
The firebase-tools npm package provides the firebase CLI executable.
npm install -g firebase-tools
firebase
underlying Google account
Firebase projects are linked to a Google account.
firebase login:list # prints current Google account
firebase login
firebase logout
list projects and select one
firebase projects:list
firebase use imagetales
project configuration and scaffolding
The init command enables several workflows, such as:
- scaffold the Cloud Functions directory
- set up and configure emulators
- add security rules for Firestore and Cloud Storage
firebase init
help
- print the list of Firebase commands.
- print the details about a given command.
firebase help
firebase help emulators:start
firebase help deploy
list deployed functions, deploy functions
firebase functions:list
firebase deploy --only functions
firebase deploy --only functions:requestPlanet
manage secrets
firebase functions:secrets:access ABC_API_KEY
firebase functions:secrets:set ABC_API_KEY
firebase functions:secrets:destroy ABC_API_KEY
start and config emulators
firebase emulators:start
firebase emulators:start --import emulator-data --export-on-exit
We specify which emulators to run with firebase.json. We set the port or rely on the default one if omitted. We scaffold this file with firebase init.
{
"emulators": {
"firestore": { "port": 8080 },
"auth": { "port": 9099 },
"functions": { "port": 5001 },
"storage": { "port": 9199 },
"ui": { "enabled": true }
},
"storage": { "rules": "storage.rules" },
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": [
/* ... */
]
}
deploy security rules
The storage emulator requires storage access rules.
- We define Storage rules in storage.rules.
- We define Firestore rules in firestore.rules
firebase deploy --only storage
firebase deploy --only firestore:rules
gcloud: Google Cloud CLI tool
gcloud enables some operations not available with the firebase tool, such as listing secrets of a given project or describing a Storage bucket.
We call gcloud from the Google Cloud Console's Cloud Shell (it is pre-installed), or we install it locally from an archive provided by Google.
gcloud secrets list --project <PROJECT_ID>
gcloud storage buckets describe gs://abcd.firebasestorage.app