Deploy to Firebase
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.
3. Declare environment variable inside run
step
-
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. -
Set the JSON file path as the value of an environment variable
$GOOGLE_APPLICATION_CREDENTIALS
declared in the shell. 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. This snippet assumes you already have a job to build your application, called build-job
, and introduces 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
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 Google Cloud Functions with Firebase, instruct CircleCI to navigate to the folder where the Google Cloud Functions are held (in this case 'functions') and run npm install
by adding the below to .circleci/config.yml
:
- run: cd functions && npm install