【问题标题】:Cloudbuild start firebase emulator then npm testCloudbuild 启动 firebase 模拟器,然后 npm 测试
【发布时间】:2021-11-16 10:27:12
【问题描述】:

我有一个可以在本地运行的设置。我可以启动模拟器,在 firestore 中加载数据,然后运行 ​​npm test。

我不确定如何在 cloudbuild 上执行此操作。到目前为止,这是我所拥有的:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  id: MOVE-DOTENV-APP-YAML
  entrypoint: bash
  args:
    - '-e'
    - '-c'
    - |
      cp functions/util/config_dev.js functions/util/config.js
      cp functions/.env_dev functions/.env
- name: node
  dir: 'functions'
  entrypoint: npm
  args: ['install']
- name: 'gcr.io/xxxx/firebase'
  args: ['emulators:start', '--only', 'functions,firestore', '&']
- name: node
  dir: 'functions'
  entrypoint: npm
  args: ['test']

我要补充的:

firebase emulators:start --only functions,firestore &
echo "Waiting for emulator to load..."
while [ $(curl http://localhost:5001/xxx/us-central1/api --silent | grep "Unauthorized" | wc -l) -eq 0 ]; do sleep 2; done
node import-db.js

关于如何实现这一点的任何想法?我还尝试构建一个 firebase 映像 (https://cloud.google.com/build/docs/deploying-builds/deploy-firebase),但它在 cloudbuild.yaml 中失败。

在模拟器开始时测试失败,输出如下(emulators:start --only functions,firestore &)(但没有错误可以告诉我发生了什么)

Pulling image: gcr.io/xxxx/firebase
Using default tag: latest
latest: Pulling from xxxx/firebase
8f04e8168e38: Already exists
82e5f66f5d0e: Already exists
c1c8f1c77d66: Already exists
5095cab27771: Already exists
ea7fe362a971: Already exists
9000ed6ad541: Already exists
79733a3c6015: Already exists
10da8f37aebc: Already exists
4641fca333ab: Already exists
f8eea1f9fdb1: Pulling fs layer
38ab87a43f87: Pulling fs layer
38ab87a43f87: Verifying Checksum
38ab87a43f87: Download complete
f8eea1f9fdb1: Verifying Checksum
f8eea1f9fdb1: Download complete
f8eea1f9fdb1: Pull complete
38ab87a43f87: Pull complete
Digest: sha256:c73a50f73c2e19952f1d64228de99ad6c26748f6242393c420b1bfee274e2832
Status: Downloaded newer image for gcr.io/xxxx/firebase:latest
gcr.io/xxxx/firebase:latest

【问题讨论】:

  • 您提到'它在 cloudbuild.yaml 中失败',这是否意味着您遇到任何错误?如果是,您能否编辑问题并提及您遇到的错误?
  • 我刚刚添加了失败的部分。不会产生错误,但是在该步骤中构建失败。
  • 您能说出您在哪里以及如何使用firebase emulators:start --only functions,firestore 命令吗?您是在 Cloudbuild.yaml 文件中还是在其他地方使用?
  • 我刚刚更新了包含模拟器的代码。我放在yaml文件里面

标签: google-cloud-platform google-cloud-build firebase-tools


【解决方案1】:

请注意,Firebase Emulator Suite 有两个要求:

  • Node.js 版本 8.0 或更高版本。
  • Java 1.8 或更高版本。

通过查看Firebase Builder Tool,图像是使用 Node 运行时构建的。由于缺少要求,尝试使用 Firebase Builder Tool 运行 Firebase Emulator Suite 会导致错误。

我的建议是构建您自己的自定义构建器或使用repository 中社区构建的以下解决方案或open issue tracker 上的解决方法。之后,您应该可以通过 Cloud Build 运行 Firebase Emulator。

【讨论】:

    猜你喜欢
    • 2018-05-21
    • 2020-09-20
    • 2015-07-02
    • 2023-03-18
    • 2020-09-09
    • 2015-05-10
    • 2012-03-03
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多