Deploying to Firebase

This page explains how to deploy applications to Firebase using Cloud Build. If you're new to Cloud Build, read the quickstarts and the Build configuration overview first.

Before you begin

  • Enable the Cloud Build, Firebase, and Resource Manager APIs.

    Enable the APIs

Required IAM permissions

  1. Open the Cloud IAM page in the Cloud Console:

    Open the Cloud IAM page

  2. Select your project and click Open.

  3. In the permissions table, locate the email ending with @cloudbuild.gserviceaccount.com, and click on the pencil icon.

  4. Add Cloud Build Service Account, Firebase Admin and API Keys Admin roles.

  5. Click Save.

Using the firebase community builder

Cloud Build provides a Firebase community builder image that you can use to invoke firebase commands in Cloud Build. To use this builder in a Cloud Build config file, you must first build the image and push it to the Container Registry in your project.

To build and push the firebase community builder:

  1. Navigate to your project root directory.

  2. Clone the cloud-builders-community repository:

    git clone https://github.com/GoogleCloudPlatform/cloud-builders-community.git
    
  3. Navigate to the firebase builder image:

    cd cloud-builders-community/firebase
    
  4. Submit the builder to your project:

    gcloud builds submit .
    
  5. Navigate back to your project root directory:

    cd ../..
    
  6. Remove the repository from your root directory:

    rm -rf cloud-builders-community/
    

Configuring the deployment

After building the firebase community builder, you can use the firebase build step in your build config file to deploy to Firebase:

  1. Create a build config file named cloudbuild.yaml or cloudbuild.json where project-id is your Cloud project ID:

    YAML

          steps:
          - name: gcr.io/project-id/firebase
            args: ['deploy', '--project=project-id', '--only=hosting']
    

    JSON

    {
      "steps": [
       {
          "name": "gcr.io/project-id/firebase",
          "args": [
             "deploy",
             "--project",
             "project-id",
             "--only",
             "hosting"
           ]
      }
      ]
    }
    
  2. Start the build using the build config file:

    gcloud builds submit --config config-file-path source-directory
    

    Where:

    • config-file-path is the path to the build config file.
    • source-directory is the path or URL to the source code.

Continuous deployment

You can automate the deployment of your software to Firebase by creating Cloud Build triggers. You can configure triggers to build and deploy images whenever you update your source code.

To automate your deployment to Firebase:

  1. In your repository, add a build config file with steps to invoke the firebase deploy command where project-id is your Cloud project ID:

    YAML

    steps:
          - name: gcr.io/project-id/firebase
            args: ['deploy', '--project=project-id', '--only=hosting']
    

    JSON

    {
      "steps": [
       {
          "name": "gcr.io/project-id/firebase",
          "args": [
             "deploy",
             "--project",
             "project-id",
             "--only",
             "hosting"
           ]
      }
      ]
    }
    
  2. Create a trigger with the build config file created in the previous step:

    1. Open the Triggers page in the Google Cloud Console:

      Open Triggers page

    2. Select your project from the project selector drop-down menu at the top of the page.

    3. Click Open.

    4. Click Create trigger.

      On the Create trigger page, enter the following settings:

      1. Enter a name for your trigger.

      2. Select the repository event to start your trigger.

      3. Select the repository that contains your source code and build config file.

      4. Specify the regex for the branch or tag name that will start your trigger.

      5. Build Configuration: Choose the build config file you created previously.

    5. Click Create to save your build trigger.

Anytime you push new code to your repository, you will automatically start a build and deploy on Firebase.

For more information on creating Cloud Build triggers, see Creating and managing build triggers.

Code example

To view a code sample for deploying to Firebase using Cloud Build, go to deploy-firebase-example.

What's next