Deploy Targets

To use the Firebase CLI to deploy the same codebase to multiple projects without having to alter your firebase.json file, set deploy targets (for example, for your staging and production projects). Currently, deploy targets are supported by Cloud Storage and Firebase Realtime Database.

Applying Deploy Targets

A deploy target is a group of resources that all share the same configuration (for instance, the same Firebase Rules). To set up a deploy target, specify the type, target name, and a list of resources:

firebase target:apply <type> <target_name> [resource1 resource2...]

Valid types are storage or database. The resources should be the bucket name or database instance names, respectively.

For example, to apply the target "main" to multiple regional Cloud Storage buckets, you might run the following command:

firebase target:apply storage main myproject.appspot.com myproject-eu myproject-in

The above command adds the following buckets to the main deploy target: myproject.appspot.com, myproject-eu, and myproject-in.

Targets are applied on a per-project basis to the currently active project. So if you're managing multiple environments with the CLI, you can configure new deploy targets for each of your projects.

Configuring firebase.json for Deploy Targets

Once you've applied deploy targets to resources, you'll need to modify your firebase.json config to reference the targets. To do this, you'll need to supply an array of configuration objects, each one specifying a target and associated configuration. Continuing the example above, your firebase.json might look like this:

{
  "storage": [
    {"target": "main", "rules": "storage.main.rules"}
  ]
}

If you have multiple configurations for your resources, you can create multiple targets and specify each one. They will all be deployed together when you call firebase deploy.

Managing Targets

You can list the targets for your current project using firebase target. To remove a resource from its target, call:

firebase target:remove storage myproject-in

This will disassociate the specified resource (myproject-in in this case) from whichever target it's been assigned. To clear an entire target by name, call:

firebase target:clear storage main

Where main is your target name.

Send feedback about...

Need help? Visit our support page.