Firebase – 无效的项目选择

huangapple go评论143阅读模式
英文:

Firebase - Invalid project selection

问题

"Debug" 步骤给出的信息如下:

项目显示名称 项目 ID 项目编号 资源位置 ID
我的项目名称 *** (current) *** europe-west

因此,我的凭据已成功访问我的项目。
但是,在下一步尝试部署时,我收到以下输出:

=== 部署到 '***'...

i 部署函数
运行命令: npm --prefix "$RESOURCE_DIR" run lint

> lint
> eslint .

✔  函数:已完成运行预部署脚本。

错误:无法获取 Firebase 项目 ***。请确保项目存在并且您的帐户具有访问权限。
错误:进程以退出代码 2 完成。

有什么办法可以修复吗?

  • 我无法在 CI 上执行 firebase login:reauth
  • 运行 firebase use ${{ secrets.FIREBASE_PROJECT_ID_DEV }} 引发相同的错误。

感谢您的帮助。

英文:

I'm using Firebase Cloud Functions for a project and I would like to automatically deploy them when I push in a specific branch on GitHub. Here is my current workflow :

name: Dev deploy

on:
  workflow_dispatch:
  push:
    branches:
      - develop

jobs:
  deploy_functions:
    name: Deploy Functions
    runs-on: ubuntu-latest
    steps:
      - name: Check out repo
        uses: actions/checkout@v3

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Cache npm
        uses: actions/cache@v1
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-16-${{ hashFiles('**/package-lock.json') }}

      - name: Node install
        run: |
          cd functions
          npm install
          npm ci          

      - name: Create SA key
        run: echo '${{ secrets.FIREBASE_CREDENTIAL_FILE_CONTENT_DEV }}' > gcloud.json

      - name: Create .firebaserc
        run: ./.github/actions-scripts/build-firebaserc.sh > .firebaserc
        env:
          PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID_DEV }}

      - name: Debug
        run: |
          cat .firebaserc
          npx firebase-tools projects:list          
        env:
          GOOGLE_APPLICATION_CREDENTIALS: gcloud.json

      - name: Deploy Cloud Functions
        run: npx firebase-tools deploy --only functions
        env:
          GOOGLE_APPLICATION_CREDENTIALS: gcloud.json

The Debug step gives me this:

Project Display Name Project ID Project Number Resource Location ID
My project name *** (current) *** europe-west

Therefore, my credentials have successfully access to my project.
However, when I try to deploy in the next step I have the output:

 === Deploying to '***'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> lint
> eslint .

✔  functions: Finished running predeploy script.

Error: Failed to get Firebase project ***. Please make sure the project exists and your account has permission to access it.
Error: Process completed with exit code 2.

Any idea how to fix it?

  • I cannot do firebase login:reauth on a CI.
  • Running firebase use ${{ secrets.FIREBASE_PROJECT_ID_DEV }} raises the same error.

Thank you for your help.

答案1

得分: 0

以下是翻译好的部分:

"看起来您正在运行多个 Firebase 项目,并且 CICD 无法找到默认项目及其凭据。因此,明确添加 Firebase 项目 ID 和 Firebase 令牌应该解决您的问题。"

"更新后的配置文件将在添加后执行以下额外步骤:"

- name: 使用 Firebase 项目
   run: npx firebase-tools use --add ${{ secrets.FIREBASE_PROJECT_ID_DEV }} --token ${{ secrets.FIREBASE_TOKEN }}

"同时,在 CI 设置中将 'FIREBASE_TOKEN' 添加到您的存储库的 secrets 中。"

"在部署 Cloud Functions 步骤中进行更新:"

- name: 部署 Cloud Functions
   run: npx firebase-tools deploy --only functions --token ${{ secrets.FIREBASE_TOKEN }}
   env:
     GOOGLE_APPLICATION_CREDENTIALS: gcloud.json

"请注意,我已经添加了 --token 以进行授权。"

"我认为这也可能会解决问题:"

  1. 运行 firebase login:ci,运行此命令将需要身份验证。完成身份验证过程后,您将在终端中生成一个 Firebase 身份验证令牌。将此令牌复制到剪贴板。

  2. 将此令牌添加到存储库的 Settings -> Secrets 中,并创建一个名为 FIREBASE_TOKEN 的新 secret,值设置为您复制的身份验证令牌。

  3. 最后,在 '部署 Cloud Functions' 步骤中添加 --token ${{ secrets.FIREBASE_TOKEN}} 标签。

  4. 然后只需提交并推送更改到您的 'develop' 分支,这将触发上述 GitHub Actions。

参考来源:在 CI 系统中使用 CLI加密的 secretsGitHub 变量

英文:

It looks like you have multiple firebase projects running and the CICD is not able to find the default project and its credentials. So Instead Adding the firebase project id and firebase token explicitly should solve your issue.

The updated config file will have the following extra step after adding :

- name: Use Firebase project         
   run: npx firebase-tools use --add ${{ secrets.FIREBASE_PROJECT_ID_DEV }} --token ${{ secrets.FIREBASE_TOKEN }}

while adding FIREBASE_TOKEN in your secret to your repository's secrets in the CI settings.
And on Deploy Cloud Functions step update:

- name: Deploy Cloud Functions
   run: npx firebase-tools deploy --only functions --token ${{ secrets.FIREBASE_TOKEN }}
   env:
     GOOGLE_APPLICATION_CREDENTIALS: gcloud.json

Notice that I have added --token to authorize.

And In my opinion this will also may solve the issue:

  1. Run firebase login:ci, running this command will require authentication and Once you complete the authentication process, you will see a Firebase authentication token generated in your terminal. Copy this token to your clipboard.

  2. And add this token to your repository's Settings -> Secrets and create a new secret with the name FIREBASE_TOKEN and the value set to the authentication token you copied.

  3. And finally add the --token ${{ secrets.FIREBASE_TOKEN }} tag in step Deploy Cloud Functions.

  4. Then just commit and push your changes to your develop branch that will trigger the above GitHub Actions.

Reference Taken from: Use the CLI with CI systems, Encrypted secrets, GitHub Variables

huangapple
  • 本文由 发表于 2023年3月7日 14:56:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658814.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定