【问题标题】:Difference between starting firestore emulator through `firebase` and `gcloud`?通过`firebase`和`gcloud`启动firestore模拟器的区别?
【发布时间】:2020-12-05 14:11:57
【问题描述】:

通过以下方式启动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 传递一个端口。这是否是两者之间较大差异的一部分,还有哪些其他差异?

【问题讨论】:

    标签: python firebase google-cloud-platform google-cloud-firestore gcloud


    【解决方案1】:

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

    使用Firebase tool,您可以启动多个 Firebase 产品的模拟器,而 gcloud command 允许您启动 GCP 模拟器。 Firestore 只是它们共同拥有的产品,因此它们的实用性应该相同或相似。

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

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

    请注意,GCP 上的 Firestore emulator 位于 beta stage 上,因此它的官方支持可能有限,并且可能会发生变化。另请注意,在 GCP's Firestore documentation 上,如何使用 Firebase CLI 而非 gcloud。

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

    【讨论】:

      猜你喜欢
      • 2022-07-19
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 2018-05-21
      • 2020-09-20
      • 2019-09-16
      • 1970-01-01
      • 2020-09-09
      相关资源
      最近更新 更多