Check for readyness
For CI we want to run the emulator suite in a docker service container (github actions). We need to able to check from the main script if the emulator is "ready". That means a couple of things:
- The emulator container will start with an empty folder. We then wait in our custom "firebase-tools" container for the
firebase.jsonto show up. - Once the
firebase.jsonhas shown up (because the main github action thread ran "checkout") we extract the location of the functionspackage.jsonand wait for it to show up. - Once the functions
package.jsonhas shown up, we can finally start the emulators, as they would crash if the functionspackage.jsonis not present (btw: it suffices to put in{}to thispackage.jsonso the check is pretty pointless...). Here is the script for step 1. - 3. The functionspackage.jsonshows up once we have run ourbuildstep. - In the main github action thread we now have to wait for the emulators to actually have loaded ALL FUNCTIONS. <--- This I do not know how to do! Currently I use
waitFor localhost:4000which returns too early! - We can run our test suite.
Is there something like http://localhost:4000/functions/health or so?
I now added a function health which just returns 200 for the time being. I mount this via the hosting emulator and ping it until it comes up. Okayish workaround.
Have you tried firebase emulators:exec './your-test-script'? It will only run the argument script once all emulators have been started, and will shutdown the emulators when done.
I've been working on this recently.
So far my approach is to use docker compose to bring up the stack (where the FB emulator suite is a dependent service) and I'm waiting for FB to be ready using depends_on and docker health checks.
version: "3.9"
services:
myapp:
build:
context: .
target: dev
container_name: myapp
volumes:
- .:/app
ports:
- "3000:3000"
environment:
NODE_ENV: dev
FIREBASE_PROJECT: demo-project
FIREBASE_AUTH_EMULATOR_HOST: fb-emulator-suite:9099
depends_on:
fb-emulator-suite:
condition: service_healthy
fb-emulator-suite:
container_name: fb-emulator-suite
image: us-central1-docker.pkg.dev/XXX/cicd/fb-emulator-suite:latest
ports:
- "4000:4000"
- "4400:4400"
- "9099:9099"
restart: always
healthcheck:
test: wget --no-verbose --tries=1 --spider http://0.0.0.0:9099/emulator/v1/projects/demo-tests/config || exit 1
interval: 60s
retries: 5
start_period: 20s
timeout: 10s
Hope it helps. As you can see, I'm polling this REST endpoint to know wether the Auth service is up and running: https://firebase.google.com/docs/reference/rest/auth#section-auth-emulator-getconfig