【发布时间】: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