Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Firebase Emulator on GitLab CI

I'm trying to test Firestore's security rules on my GitLab CI pipeline. I need to run Firebase's emulator to accomplish that.

However, the Firebase emulator basically starts serving a "fake backend". So, how can I run that job in parallel to other jobs?

For example:

stages:
  - emulator
  - test

emulator:
  - stage: emulator
  script:
    - firebase serve --only firestore

test:
  - stage: test
  script:
    - yarn test

The test stage is never reached as GitLab is serving the emulator stage. Therefore, it never finishes.

like image 302
Will Halpert Avatar asked Jun 11 '19 21:06

Will Halpert


1 Answers

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"

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

like image 68
Jürgen Brandstetter Avatar answered Oct 12 '22 08:10

Jürgen Brandstetter