在 GitLab CI 上运行 Firebase 模拟器 [英] Running Firebase Emulator on GitLab CI
问题描述
我正在尝试在我的 GitLab CI 管道上测试 Firestore 的安全规则.我需要运行 Firebase 的模拟器来完成.
I'm trying to test Firestore's security rules on my GitLab CI pipeline. I need to run Firebase's emulator to accomplish that.
但是,Firebase 模拟器基本上开始提供假后端".那么,我怎样才能使该作业与其他作业并行运行?
However, the Firebase emulator basically starts serving a "fake backend". So, how can I run that job in parallel to other jobs?
例如:
stages:
- emulator
- test
emulator:
- stage: emulator
script:
- firebase serve --only firestore
test:
- stage: test
script:
- yarn test
test
阶段永远不会到达,因为 GitLab 正在为 emulator
阶段提供服务.因此,它永远不会结束.
The test
stage is never reached as GitLab is serving the emulator
stage. Therefore, it never finishes.
推荐答案
你不应该使用 2 个阶段.请记住,每个阶段都是从某个地方开始的完全独立的计算机".因此,一个阶段默认情况下不能与另一个阶段交互.阶段的 script
部分实际上是一个 shell 脚本.因此,如果您想尝试一切是否正常,请创建一个 shell 脚本并执行它.
You should not use 2 stages. Keep in mind, each stage is a completely independent "computer" started somewhere. So one stage can per default not interact with another.
The script
part of a stage is practically a shell script. So if you want to try if everything works, create a shell script and execute it.
这就是我所做的.请记住,我没有使用您的特定设置对其进行测试
Here is what I did. Keep in mind it's I didn't test it with your particular setup
stages:
- test
test:
- stage: test
script:
- yarn compile
- yarn firebase setup:emulators:firestore
- yarn firebase emulators:exec -P dev1 --only firestore "yarn test --exit"
要在 CI
系统上使用模拟器进行测试,最好添加一个启动"脚本.在这种情况下,我添加了测试 yarn test --exit
To use the emulator with tests on a CI
system it's best you add a "start" script. In this case I'm adding the test yarn test --exit
这篇关于在 GitLab CI 上运行 Firebase 模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!