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.
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
-
Inside a
runstep, 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_CREDENTIALSdeclared 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
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