简体   繁体   中英

Login to firebase using gcloud service account

I have functions deployed to gcloud functions and i want to configure CI/CD for deploying this functions from gitlab. To do any operations from gitlab i need to get firebase auth token with

firebase login:ci

command.

The problem is that i need to get this token using gcloud service account, which is not displayed in browser, when i run

firebase login:ci

I have this service account data ( project_id , private_key , private_key_id , etc.)

How should i authorize using this acc?

If you set an environment variable called GOOGLE_APPLICATION_CREDENTIALS as a path pointing to your service account JSON file, the Firebase CLI will automatically pick that up and use it to authorize commands. You don't need to be logged in or provide a --token argument when this is the case.

If anyone finds this and is wondering how to do it on CircleCI, this worked for me.

  1. Generate a json file key for you service account in the GCP Console
  2. Set the json to a CircleCI environment variable at the org level or the project level
    • We use one at the org level called GSA_KEY
  3. In your workflow config, before you run the firebase command, run this command:
    • echo echo $GSA_KEY > "$HOME"/gcloud.json
  4. Then run your firebase deploy command, first setting the path to GOOGLE_APPLICATION_CREDENTIALS

The deployment run looks like:

steps:
  - checkout
  - run:
      name: Create SA key JSON
      command: echo $GSA_KEY > "$HOME"/gcloud.json
  - run:
      name: Deploy to Firebase
      command:
        GOOGLE_APPLICATION_CREDENTIALS="$HOME"/gcloud.json firebase deploy [project specific stuff]

使用命令:

gcloud auth activate-service-account xyz@project-id.iam.gserviceaccount.com  --key-file=/path/to/file.json --project=project-id
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json"

in Bash

run the following commands 1 and 2 in order

  1. export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json"

"/path/to/file.json" -- the location of the file where the service account json file is saved.

  1. npx firebase-tools deploy --json

Do not forget to use the right project when deploying like firebase use dev or firebase use qa

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM