通过 `firebase` 和 `gcloud` 启动 firestore 模拟器的区别?

Difference between starting firestore emulator through `firebase` and `gcloud`?

通过以下方式启动firestore模拟器有什么区别:

firebase emulators:start --only firestore

和:

gcloud beta emulators firestore start

这两个选项都允许我的 python 应用程序实现与数据库的连接,如下所示:

import google
from google.cloud import firestore

os.environ["FIRESTORE_EMULATOR_HOST"] = "localhost:8081"
os.environ["FIRESTORE_EMULATOR_HOST_PATH"] = "localhost:8081/firestore"
os.environ["FIRESTORE_HOST"] = "http://localhost:8081"

credentials = mock.Mock(spec=google.auth.credentials.Credentials)
client = firestore.Client(credentials=credentials)

我自己注意到的一个区别是 firebase 似乎尊重我的 firebase.json,特别是像这样指定的主机端口:

{
  "emulators": {
    "firestore": {
      "port": "8081"
    }
  }
}

另一方面,gcloud 忽略 firebase.json 而是选择一个随机端口,除非我明确地通过 --host-port 传递一个端口。这部分是不是两者比较大的区别,还有哪些区别?

我一直在查看这两种工具的文档,发现它们的作用几乎相同。

使用 Firebase tool you can start emulators for multiple Firebase products whereas the gcloud command 可以启动 GCP 模拟器。 Firestore 只是它们共同拥有的产品,因此它们的实用性应该相同或相似。

关于功能差异,firebase 提供了 --import--export-on-exit 标志,允许您在模拟会话之间保存和恢复数据。它还提供了一种可视化 security rules 如何处理当前查询的方法。

除了这些功能之外,我还要注意设置端口和规则文件的不同方法:

请注意 Firestore emulator on GCP is on the beta stage thus it may have limited official support and may be subject to change. Also notice how, on GCP's Firestore documentation,使用 Firebase CLI 而不是 gcloud。

最后你应该使用你喜欢的工具,因为它们都朝着模拟 Firestore 的相同目标努力。如果您已经在使用 Firebase CLI,我建议您继续使用它;如果您正在使用 gcloud,请使用它。