Documentation structure for LLMs (llms.txt)

Deploy to Firebase

Cloud Server v4+

In this how-to guide, you will learn how to configure CircleCI to deploy to Firebase.

Introduction

This page provides a configuration for deployment to Firebase. In order to deploy to Firebase you will need to add firebase-tools to your project’s devDependencies since attempting to install firebase-tools globally in CircleCI will not work.

1. Install tools

npm install --save-dev firebase-tools

2. Authenticate with a service account

If you have not already done so, create a Google Cloud service account with the appropriate access for the deploy job.

Then, create a service account key. You may store the key file contents in your project’s environment variables (in this guide, we name the project environment variable $SA_KEY). Refer to the Set an Environment Variable in a Project guide for instructions. CircleCI will use this credential to authenticate with Firebase.

To take advantage of secrets masking, it is best practice to set environment variables at the project level or within a context.
Review the Google IAM documentation for best practices in managing service account keys.

3. Declare environment variable inside run step

  1. Inside a run step, output the value of the environment variable, that is, the contents of the service account key file, to a JSON file.

  2. Set the JSON file path as the value of an environment variable $GOOGLE_APPLICATION_CREDENTIALS declared in the shell (See Environment Variables Order of Precedence) guide. Then, run the Firebase deploy command.

    - run:
        name: Deploy on Firebase
        command: |
          echo $SA_KEY > credentials.json
          GOOGLE_APPLICATION_CREDENTIALS=credentials.json firebase deploy

To learn more about how Google finds application credentials, refer to the documentation for Google Cloud authentication.

Deploy example

The following example shows how you can add a Firebase deploy job to your project’s .circleci/config.yml file. The example includes the following:

  • A job to build your application (build-job).

  • A deployment workflow that only runs the deployment job once the build job has completed and you are on the main branch.

version: 2.1

jobs:
  build-job:
    docker: # Specify executor for running build-job - this example uses a Docker container
      - image: <docker-image-name-tag> # Specify docker image to use
    steps:
      # steps omitted for brevity

  deploy-job:
    docker:
      - image: <docker-image-name-tag>
    working_directory: /tmp/my-project
    steps:
      - run:
          name: Deploy on Firebase
          command: |
            echo $SA_KEY > credentials.json
            GOOGLE_APPLICATION_CREDENTIALS=credentials.json firebase deploy

workflows:
  deploy:
    jobs:
      - build-job
      - deploy-job:
          requires:
            - build-job
          filters:
            branches:
              only: main

Google Cloud Functions

If you are using Cloud Functions with Firebase, you should do the following:

  • Instruct CircleCI to navigate to the folder where the Cloud Functions are held (in this case 'functions') and run npm install.

  • Add the following to your .circleci/config.yml file:

        - run: cd functions && npm install

Track your deployments with deploy markers

Deploy markers provide a way to track and manage your Firebase deployments in the CircleCI web app. When you add deploy markers to your deployment job, you can view a timeline of all deployments, track their status, and enable rollback and deploy pipelines.

You have two options for setting up deploy markers:

  • In-app setup: Use the guided setup in the CircleCI web app when configuring a Rollback Pipeline or Deploy Pipeline. The setup will walk you through adding deploy markers to your configuration. If you are using GitHub and have the CircleCI GitHub App installed, you can use AI to generate the deploy marker configuration automatically.

  • Manual setup: Add deploy marker commands directly to your .circleci/config.yml file by following the Configure Deploy Markers guide.

Both approaches will enable you to track deployment history and manage rollbacks directly from the CircleCI web app.