CLI tool
The Firebase CLI tool enables several workflows:
- we emulate the Firebase backend locally, to run it and debug it at no cost: authentication, databases, storage and serverless functions.
- It is the only tool to set up the Cloud Functions' directory, and deploy them.
- we provide secrets to Google, and manage them. We register and deploy security rules.
- we list the Firebase projects linked to the Google account.
the CLI executable
The firebase CLI executable is provided by the firebase-tools npm package.
npm install -g firebase-tools
firebase
Google account
Firebase projects are scoped to a Google account.
firebase login
firebase login:list # prints current Google account
firebase logout
list projects and select one
firebase projects:list
firebase use imagetales
project configuration and scaffolding
The init command enables several workflows:
- scaffold the Cloud Functions directory
- set up and configure the emulators
- add security rules for Firestore and Cloud Storage
- set up Firebase Hosting to deploy static web apps
firebase init
help
The general help prints all commands. We may also target specific commands.
firebase help
firebase help | grep functions
firebase help | grep firestore
firebase help emulators:start
firebase help deploy
cloud functions and secrets
firebase init
firebase functions:list
firebase functions:shell
firebase functions:secrets:access ABC_API_KEY
firebase functions:secrets:set ABC_API_KEY
firebase functions:secrets:destroy ABC_API_KEY
firebase deploy --only functions
firebase deploy --only functions:requestPlanet
emulators
firebase emulators:start
firebase emulators:start --import emulator-data --export-on-exit
We specify which emulators to run in firebase.json. We may provide the port, or an empty object to use the default port. We may 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": [
/* ... */
]
}
security rules and rule deployment
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 in the firebase tool, such as listing secrets of a given project or describing a Storage bucket.
Note: we install gcloud from an archive provided by Google, not from the deprecated npm package.
gcloud secrets list --project <PROJECT_ID>
gcloud storage buckets describe gs://abcd.firebasestorage.app