Closed7
Firebase Functions をデプロイしようとしたら `Unable to retrieve the repository metadata ~`が発生する
まとめ
- Firebase Functions をデプロイしようとしたらエラーが発生した
- 必要な API を有効化 & IAM ロールを付与したらエラーが解消した
やろうとしたこと
firebase init functions
firebase deploy --only functions
発生したエラー
Unable to retrieve the repository metadata for projects/ukkari-reminder/locations/us-central1/repositories/gcf-artifacts. Ensure that the Cloud Functions service account has 'artifactregistry.repositories.list' and 'artifactregistry.repositories.get' permissions. You can add the permissions by granting the role 'roles/artifactregistry.reader'.
出力
$ firebase deploy --only functions
=== Deploying to 'ukkari-reminder'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> eslint --ext .js,.ts .
Running command: npm --prefix "$RESOURCE_DIR" run build
> build
> tsc
✔ functions: Finished running predeploy script.
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8674
i functions: preparing functions directory for uploading...
i functions: packaged /Users/nix/ghq/github.com/mitsuoka0423/ukkari-reminder/functions (95.17 KB) for uploading
i functions: ensuring required API run.googleapis.com is enabled...
i functions: ensuring required API eventarc.googleapis.com is enabled...
i functions: ensuring required API pubsub.googleapis.com is enabled...
i functions: ensuring required API storage.googleapis.com is enabled...
✔ functions: required API pubsub.googleapis.com is enabled
⚠ functions: missing required API run.googleapis.com. Enabling now...
✔ functions: required API storage.googleapis.com is enabled
⚠ functions: missing required API eventarc.googleapis.com. Enabling now...
✔ functions: required API run.googleapis.com is enabled
✔ functions: required API eventarc.googleapis.com is enabled
i functions: generating the service identity for pubsub.googleapis.com...
i functions: generating the service identity for eventarc.googleapis.com...
✔ functions: functions folder uploaded successfully
i functions: creating Node.js 18 (2nd Gen) function helloWorld(us-central1)...
Unable to retrieve the repository metadata for projects/ukkari-reminder/locations/us-central1/repositories/gcf-artifacts. Ensure that the Cloud Functions service account has 'artifactregistry.repositories.list' and 'artifactregistry.repositories.get' permissions. You can add the permissions by granting the role 'roles/artifactregistry.reader'.
Functions deploy had errors with the following functions:
helloWorld(us-central1)
i functions: cleaning up build files...
Error: There was an error deploying functions
今回の原因
- 必要な API が有効化されていない
やること/手順
- https://console.cloud.google.com/functions/list?project=ukkareminder にアクセスする
-
関数を作成
を選択 -
有効にする
を選択
無事デプロイされました(赤いけど一旦デプロイできたのでOK)
ちゃんとデプロイされてなかったので、エラーを解消する
赤いのを解消する
- エラーメッセージに「サービスアカウントに
artifactregistry.repositories.list
とartifactregistry.repositories.get
権限があることを確認してください」と書いてあるので、付与する
やること
IAM ロールの付与
-
https://console.cloud.google.com/iam-admin/iam から対象プロジェクトを開き、サービスアカウントを探す
-
Artifact Registry 読み取り
ロールを追加
関数の削除/デプロイ
一度関数を削除しないといけないようです
-
firebase functions:list
で削除対象の関数名を見つける
firebase functions:list 1 ↵ ──(Sat,Dec30)─┘
┌────────────┬─────────┬─────────┬─────────────┬────────┬──────────┐
│ Function │ Version │ Trigger │ Location │ Memory │ Runtime │
├────────────┼─────────┼─────────┼─────────────┼────────┼──────────┤
│ helloWorld │ v2 │ https │ us-central1 │ --- │ nodejs18 │
└────────────┴─────────┴─────────┴─────────────┴────────┴──────────┘
-
firebase functions:delete {関数名}
で関数を削除
firebase functions:delete helloWorld ──(Sat,Dec30)─┘
? You are about to delete the following Cloud Functions:
helloWorld(us-central1)
Are you sure? Yes
i functions: deleting Node.js 18 (2nd Gen) function helloWorld(us-central1)...
✔ functions[helloWorld(us-central1)] Successful delete operation.
i functions: cleaning up build files...
⚠ functions: Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually at https://console.cloud.google.com/artifacts/docker/ukkari-reminder/us-central1/gcf-artifacts
- 再デプロイ
firebase deploy --only functions ──(Sat,Dec30)─┘
=== Deploying to 'ukkari-reminder'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> eslint --ext .js,.ts .
Running command: npm --prefix "$RESOURCE_DIR" run build
> build
> tsc
✔ functions: Finished running predeploy script.
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
✔ functions: required API cloudbuild.googleapis.com is enabled
i functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8283
i functions: preparing functions directory for uploading...
i functions: packaged /Users/nix/ghq/github.com/mitsuoka0423/ukkari-reminder/functions (95.17 KB) for uploading
i functions: ensuring required API run.googleapis.com is enabled...
i functions: ensuring required API eventarc.googleapis.com is enabled...
i functions: ensuring required API pubsub.googleapis.com is enabled...
i functions: ensuring required API storage.googleapis.com is enabled...
✔ functions: required API eventarc.googleapis.com is enabled
✔ functions: required API storage.googleapis.com is enabled
✔ functions: required API run.googleapis.com is enabled
✔ functions: required API pubsub.googleapis.com is enabled
i functions: generating the service identity for pubsub.googleapis.com...
i functions: generating the service identity for eventarc.googleapis.com...
✔ functions: functions folder uploaded successfully
i functions: creating Node.js 18 (2nd Gen) function helloWorld(us-central1)...
✔ functions[helloWorld(us-central1)] Successful create operation.
Function URL (helloWorld(us-central1)): https://helloworld-c7dtksxnsa-uc.a.run.app
i functions: cleaning up build files...
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/ukkari-reminder/overview
次こそはOK
このスクラップは6ヶ月前にクローズされました