20

I'm trying to figure out how to deploy to Firebase Hosting using CircleCI. As far as I know, there is no way to setup deployment with an SSH key, so I'm trying to find a way of logging into Firebase during deployment and push the code. What I have tried so far is the following in my circle.yml:

// circle.yml
deployment:
  production:
    branch: circle-deploy
    commands:
      - npm install -g firebase-tools
      - firebase login | echo -e "${FIREBASE_EMAIL}\n${FIREBASE_PASSWORD}"
      - firebase deploy

However, I keep getting the following error and I'm not sure how to remedy it.

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: write EPIPE
    at errnoException (net.js:904:11)
at Object.afterWrite (net.js:720:19)
erichrusch
  • 1,323
  • 10
  • 18

5 Answers5

38

I just had to do this and there is a easier way

  1. On your machine, you can get your access token by typing

    firebase login:ci
    
  2. Save that token as an environment variable in circleci, $FIREBASE_TOKEN
  3. For your deploy step, you can skip the login:

    deployment:
      production:
        branch: master
        commands:
          - firebase deploy --token=$FIREBASE_TOKEN --non-interactive
    
mattmcmanus
  • 1,786
  • 2
  • 18
  • 27
16

A small addition to the other answers above...

In order to avoid installing firebase-tools globally in circle ci on every build:

Modify your package.json file to include firebase-tools as a dev dependency like so:

npm install --save-dev firebase-tools

Then in your circle.yml file:

deployment:
  production:
    branch: master
    commands:
      - ./node_modules/.bin/firebase deploy --token=$FIREBASE_TOKEN --non-interactive
Ilan Klinghofer
  • 860
  • 8
  • 10
7

For anyone else who stumbles upon this question, these are the steps I had to take to get CircleCI (and presumably any other CI) working with Firebase Hosting.

  1. Generate a CI token: firebase login:ci
  2. Save that token as an ENV var (FIREBASE_TOKEN)
  3. Use the token in your deploy script: firebase deploy --token=$FIREBASE_TOKEN --non-interactive

Firebase added the login:ci recently to prevent people from using personal deploy tokens for CI services.

Taylor Glaeser
  • 1,338
  • 12
  • 18
3

This is my initial setup, deploy only master, skip tests

  1. run npm install -g firebase-tools on your local machine
  2. run firebase login:ci to get the token on your local machine
  3. run firebase init. This will create firebase.json make sure it is committed
  4. configure FIREBASE_TOKEN in Environment Variables in BUILD SETTINGS of the project on circileci

//circle.yml

general:
  branches:
    only:
      - master

test:
  override:
    - echo "test"

deployment:
  production:
    branch: master
    commands:
      - npm install -g firebase-tools
      - firebase deploy --token=$FIREBASE_TOKEN --non-interactive
Ravi
  • 166
  • 1
  • 2
1

Here is the process we followed to deploy to CircleCi.

  1. Store your username and password as environment variables at the project level in CircleCi.

  2. Edit your circle.yml

    deployment:
      production:
        branch: your_branch
        commands:
          - npm install -g firebase-tools
          - firebase login --email $FIREBASE_USERNAME --password $FIREBASE_PASSWORD
          - firebase deploy
    
  3. Push to your branch

Seems to work fine.

brice
  • 24,329
  • 7
  • 79
  • 95
erichrusch
  • 1,323
  • 10
  • 18