移行後のベスト プラクティス

Firebase Extensions から関数キットに移行すると、キット インスタンスは Firebase プロジェクトの標準の第 2 世代 Cloud Functions として管理されます。このガイドでは、既存の拡張機能を移行せずに npm から新しい関数キットを直接インストールする方法、キット パラメータとグローバル オプションを更新する方法、パブリッシャーがアップデートをリリースしたときに npm パッケージのバージョンをアップグレードする方法、必要に応じて移行をロールバックする方法について説明します。

移行せずに npm パッケージの関数キットを使用する

拡張機能から移行しない場合、関数キットの使用は次の 2 つの部分で構成されます。

キットの取り付け

関数キットをインストールするには、次の CLI コマンドを使用します。

firebase functions:kits:install --package <npm-package-name>

実施例:

firebase functions:kits:install --package @firebase-function-kits/firestore-bigquery-export --project my-project
✔ What would you like to name this kit? firestore-bigquery-export
✔ What would you like to name this instance? firestore-bigquery-export
i  function-kits/firestore-bigquery-export/source/package.json is unchanged
i  function-kits/firestore-bigquery-export/source/tsconfig.json is unchanged
i  function-kits/firestore-bigquery-export/source/.gitignore is unchanged
i  functions: Running npm install @firebase-function-kits/firestore-bigquery-export@next --save-prefix=^...
i  functions: Building TypeScript source...
✔  Wrote configuration info to firebase.json

i  functions: Loaded environment variables from function-kits/firestore-bigquery-export/config-firestore-bigquery-export/.env.my-project
Prompting for parameters for codebase firestore-bigquery-export:
✔ Enter a string value for FUNCTION_DEFAULT_REGION:
(Global default region where functions should be deployed. Can be overridden per-function.) us-east1

✔ Enter a string value for BigQuery Project ID:
(Override the default project for BigQuery instance. This can allow updates to be directed to a BigQuery
instance on another GCP project.) my-bigquery-project

✔ Enter a string value for Firestore Instance ID:
(The Firestore database to use. Use "(default)" for the default database. You can view your available
Firestore databases at https://console.cloud.google.com/firestore/databases.) eu-testing

# Omitting many more parameters for brevity

✔  Wrote configuration info to firebase.json
✔  functions: Function kit firestore-bigquery-export successfully installed.

i  functions: At the first deploy, the following functions will be created in your project:
- kit-firestore-bigquery-export-fsexportbigquery
- kit-firestore-bigquery-export-initBigQuerySync
- kit-firestore-bigquery-export-setupBigQuerySync
i  functions: At the first deploy, the following Task Queues will be created in your project:
- kit-firestore-bigquery-export-initBigQuerySync
- kit-firestore-bigquery-export-setupBigQuerySync
i  functions: At the first deploy, the following APIs will be enabled in your project:
- bigquery.googleapis.com
- cloudtasks.googleapis.com
i  functions: At the first deploy, the following roles will be granted to the kit service account:
- BigQuery Data Editor
- BigQuery User
- Cloud Datastore User
- Eventarc Event Receiver
- roles/run.invoker
⚠  functions: Please review the changes above. If you do not want them applied to your project, uninstall this kit before running firebase deploy.

デフォルトのグローバル オプションを変更する

キット インスタンスのグローバル オプションを構成するには、function-kits/<your-kit-id>/source/src/index.ts にある index.ts ファイルを変更します。

キットのすべてのインスタンスでデフォルトを共有する場合は、index.ts で直接設定します。それ以外の場合は、index.ts に記載されている例と手順に沿って、インスタンスごとに設定されるパラメータを作成します。

キットのデプロイ

関数キットをデプロイするには、次のコマンドを実行します。

firebase deploy --only functions:<kit-instance-id>

実施例:

firebase deploy --only functions:firestore-bigquery-export --project my-project

出力:

=== Deploying to 'my-project'...

i  deploying functions
i  functions: Loaded environment variables from function-kits/firestore-bigquery-export/config-firestore-bigquery-export/.env.my-project
i  functions: ensuring required API bigquery.googleapis.com is enabled...
i  functions: ensuring required API cloudtasks.googleapis.com is enabled...
✔  functions: required APIs are enabled
i  functions: granting declarative IAM roles to managed service account:
   - BigQuery Data Editor
   - BigQuery User
   - Cloud Datastore User
   - Eventarc Event Receiver
   - roles/run.invoker
✔  functions: successfully granted IAM roles
i  functions: creating Node.js 22 (2nd Gen) function kit-firestore-bigquery-export-fsexportbigquery(us-central1)...
i  functions: creating Node.js 22 (2nd Gen) function kit-firestore-bigquery-export-initBigQuerySync(us-central1)...
i  functions: creating Node.js 22 (2nd Gen) function kit-firestore-bigquery-export-setupBigQuerySync(us-central1)...
✔  functions[kit-firestore-bigquery-export-fsexportbigquery(us-central1)] Successful create operation.
✔  functions[kit-firestore-bigquery-export-initBigQuerySync(us-central1)] Successful create operation.
✔  functions[kit-firestore-bigquery-export-setupBigQuerySync(us-central1)] Successful create operation.
i  functions: Executing afterFirstDeploy lifecycle hook targeting: kit-firestore-bigquery-export-initBigQuerySync...
✔  functions: Successfully queued task for lifecycle hook kit-firestore-bigquery-export-initBigQuerySync in queue projects/my-project/locations/us-central1/queues/kit-firestore-bigquery-export-initBigQuerySync.

✔  Deploy complete!

キットをインストールしてデプロイすると、次の処理が行われます。

  • function-kits/firestore-bigquery-export/source を作成します。これには、キットの各インスタンスで異なる場所を選択できるパラメータを設定しながら、キット パッケージをインポートおよびエクスポートする基本的な index.ts ファイルを含むキットソースが含まれます。
  • function-kits/firestore-bigquery-export/config-firestore-bigquery-export/.env.<project-id> を作成し、関数に入力された構成データを入力します。今後の更新で新しいパラメータが追加された場合は、次のデプロイ時にプロンプトが表示されます。
  • このキットを実行するために必要な Google Cloud リソース(特定の IAM ロールを持つサービス アカウント、関数、Eventarc トリガー、Cloud Tasks キューなど)を作成します。

同じプロジェクトにキットのインスタンスが複数ある場合は、これらのコマンドを繰り返して、同じキットの新しいインスタンスを作成してデプロイできます。また、単一のキット インスタンスを、構成が異なる複数の Firebase プロジェクト(ステージング プロジェクトや本番環境プロジェクトなど)にデプロイすることもできます。高度な設定の詳細については、高度な移行をご覧ください。

キットのアンインストール

キットとそのすべてのインスタンスを削除するには、次のコマンドを実行します。

firebase functions:kits:uninstall --kit <kit-id>

これにより、すべてのインスタンスとその構成が削除され、キットソースがディスクから削除されます。

キットの 1 つのインスタンスのみを削除するには、次のコマンドを実行します。

firebase functions:kits:uninstall --instance <kit-instance-id>

キットのインスタンスが 1 つしかない場合は、キット全体がアンインストールされます。

キット構成の更新

インストール時または初回デプロイ時に、キットのすべてのパラメータを構成するよう求められます(拡張機能から構成を移行した場合を除く)。これらのパラメータは、キット インスタンス構成ディレクトリの .env ファイルに保存されます。たとえば、プロジェクト my-project に firestore-bigquery-export という名前のキット インスタンスがある場合、.env ファイルは function-kits/firestore-bigquery-export/config-firestore-bigquery-export/.env.my-project にあります。

次のように表示されます。

DATASET_LOCATION=us
BIGQUERY_PROJECT_ID=my-project
DATABASE=eu-testing
DATABASE_REGION=eur3
COLLECTION_PATH=posts
WILDCARD_IDS=false
DATASET_ID=firestore_export
TABLE_ID=posts
TABLE_PARTITIONING=NONE
TIME_PARTITIONING_FIELD=
TIME_PARTITIONING_FIRESTORE_FIELD=
TIME_PARTITIONING_FIELD_TYPE=omit
CLUSTERING=
MAX_DISPATCHES_PER_SECOND=100
VIEW_TYPE=view
MAX_STALENESS=
REFRESH_INTERVAL_MINUTES=
BACKUP_COLLECTION=
TRANSFORM_FUNCTION=
USE_NEW_SNAPSHOT_QUERY_SYNTAX=no
EXCLUDE_OLD_DATA=no
KMS_KEY_NAME=
MAX_ENQUEUE_ATTEMPTS=3
LOG_LEVEL=info
FUNCTION_DEFAULT_REGION=us-west1

変更する構成値がわかっている場合は、.env ファイルで直接編集できます。インストールとデプロイ中に実行されるインタラクティブ プロンプトを使用する場合は、変更するパラメータを .env ファイルから削除して、キット インスタンスを再デプロイします。これらのパラメータは、デプロイ時に指定するよう求められます。

たとえば、行 COLLECTION_PATH=posts を削除してデプロイすると、デプロイ中にプロンプトが表示されます。

i functions: Loaded environment variables from function-kits/firestore-bigquery-export/config-firestore-bigquery-export-d9cd/.env.ajp-testing
Prompting for parameters for codebase firestore-bigquery-export:

Collection path: What is the path of the collection that you would like to export? You may use {wildcard} notation to match a subcollection of all documents in a collection (for example: chatrooms/{chatid}/posts). Parent Firestore Document IDs from {wildcards} can be returned in path_params as a JSON formatted string.
? Enter a string value for Collection path: (posts)

機能キットのメンテナンスとアップグレード

パブリッシャーは、バグの修正、機能の追加、依存関係の更新、セキュリティの脆弱性への対処のために、npm パッケージを随時更新することがあります。これらのリリースを常に最新の状態に保ち、更新プログラム(特にセキュリティの脆弱性に対処するもの)をインストールすることをおすすめします。

functions:kits:install コマンドは、キットを npm パッケージとしてインストールし、キットのインスタンスごとにすべての関数をエクスポートするコードベースを作成します。キットをアップグレードするには、パッケージ バージョンを更新してから、キットの各インスタンスを再デプロイして変更を適用します。

キットにアップデートがあるかどうかを判断する

function-kits/<your-kit-id>/source でキットの source ディレクトリに移動します。この source ディレクトリから次のコマンドを実行して、関数キットと Cloud Functions SDK を含む、すべての古い npm パッケージに関するレポートを取得します。

npm outdated

GitHub の Dependabot など、更新が必要な依存関係を特定するツールをすでに使用している場合は、キット ディレクトリをそのワークフローに統合することをおすすめします。

キットの更新

キットとその依存関係を最新の非破壊バージョン(破壊的変更を含む可能性があるメジャー バージョンの更新を除く)に更新するには、次のコマンドを実行します。

npm update --save

関数キット パッケージのみを更新し、他のパッケージは更新しない場合は、パッケージ名を npm update に渡します。

npm update <package-name> --save

パッケージを最新のメジャー バージョン(互換性を損なう変更が導入される可能性がある)にアップグレードするには、次のコマンドを実行します。

npm update --save <npm-package-name>@latest

パッケージのドキュメントとリリースノートを確認して、変更内容と、破壊的変更を防ぐためにデプロイの前後に必要な追加の手順があるかどうかを確認します。

更新されたインスタンスのデプロイ

npm update を実行すると、ローカルのソースコードのみが更新されます。クラウドで実行中の関数を更新するには、関数を再デプロイします。次のコマンドを実行すると、すべての関数キットを含む、プロジェクト内のすべての関数を再デプロイできます。

firebase deploy --only functions

移行を元に戻す

移行を元に戻すには、まず拡張機能を再インストールします。キットの .env ファイルを使用して、インストール時に必要な構成値を確認できます。

拡張機能をデプロイしたら、キット インスタンスをアンインストールします(これが残りの最後のインスタンスである場合は、キット全体がアンインストールされます)。

firebase functions:kits:uninstall --instance <kit-instance-id> --project <project-id>

将来の移行のために拡張機能の構成を保存する

2027 年 3 月 31 日以降は、既存の拡張機能構成を取得できなくなります。2027 年 3 月 31 日までに移行できない場合は、この日以降に移行することになった場合に備えて、拡張機能を保存しておくことを強くおすすめします。

  1. 拡張機能インスタンス ID のリストを取得します。

    ext:list CLI コマンドを使用すると、Firebase プロジェクト内のすべての拡張機能インスタンスのリストを取得できます。

    firebase ext:list --project <project-id>
    

    実施例:

    firebase ext:list --project my-project
    
    » firebaselocal ext:list
    i  extensions: ensuring required API firebaseextensions.googleapis.com is enabled...
    i  extensions: list of extensions installed in ajp-testing:
    ┌────────────────────────────────────┬───────────┬────────────────────────────────┬────────┬─────────┬─────────────────────┬───────────────────────────────────────────────────┐
    │ Extension                          │ Publisher │ Instance ID                    │ State  │ Version │ Your last update    │ Replacement Kit                                   │
    ├────────────────────────────────────┼───────────┼────────────────────────────────┼────────┼─────────┼─────────────────────┼───────────────────────────────────────────────────┤
    │ firebase/firestore-bigquery-export │ firebase  │ firestore-bigquery-export-zbrp │ ACTIVE │ 0.3.3   │ 2026-09-06 22:31:04 │ @firebase-function-kits/firestore-bigquery-export │
    ├────────────────────────────────────┼───────────┼────────────────────────────────┼────────┼─────────┼─────────────────────┼───────────────────────────────────────────────────┤
    │ firebase/firestore-bigquery-export │ firebase  │ firestore-bigquery-export      │ ACTIVE │ 0.3.2   │ 2026-06-03 17:41:24 │ @firebase-function-kits/firestore-bigquery-export │
    └────────────────────────────────────┴───────────┴────────────────────────────────┴────────┴─────────┴─────────────────────┴───────────────────────────────────────────────────┘
    ⚠ Notice: Firebase Extensions will shut down on March 31, 2027. Learn more: https://firebase.google.com/docs/extensions/faq-and-troubleshooting
    

    ext:list コマンドには JSON 出力形式もあります。ユーティリティ jq がインストールされている場合は、これを使用してプロジェクトのすべてのインスタンス ID のリストを取得できます。

    firebase ext:list --json --project <project-id> | jq -r '.result[].instanceId'
    

    実施例:

    firebase ext:list --json --project my-project | jq -r '.result[].instanceId'
    

    出力:

    firestore-bigquery-export-zbrp
    firestore-bigquery-export
    
  2. 各インスタンスの構成をエクスポートします。

    インスタンスごとに、次のエクスポート コマンドを実行して、構成をディスクに保存できます。

    firebase ext:export --mode functions --project <project-id> --instance <your-instance-id>
    

    実施例:

    firebase ext:export --mode functions --project my-project --instance firestore-bigquery-export
    

    出力:

    i  extensions: ensuring required API firebaseextensions.googleapis.com is enabled...
    i  functions: Saving exported extensions config as a Function Kits .env file
    i  functions: Created new local file firestore-bigquery-export/.env.testing to store param values. We suggest explicitly adding or excluding this file from version control.
    i  functions: Loaded environment variables from firestore-bigquery-export/.env.testing
    i  functions: Loaded environment variables from firestore-bigquery-export/.env.testing
    i  functions: Writing new parameter values to disk: firestore-bigquery-export/.env.testing
    

    ディスクには、<instance-id>/.env.<project-id> のような場所にこの拡張機能インスタンスのエクスポートがあります。この例では、firestore-bigquery-export/.env.my-project にあります。

    このプロセスはインスタンスごとに 1 回繰り返すことができます。これにより、すべての拡張機能インスタンス構成を含む .env ファイルのセットが作成されます。このファイルは、移行の一部として後で再利用できます。

  3. エクスポートした .env ファイルをより適切な場所に移動します。

    拡張機能からエクスポートされた .env ファイルは Firebase プロジェクトに直接配置されますが、関数キットに移行していない場合は、日常的に必要になることはありません。将来必要になるまで、または削除するまで、プロジェクトから他の適切な保存場所に移動できます。