Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for readyness #5009

Open
levino opened this issue Sep 23, 2022 · 3 comments
Open

Check for readyness #5009

levino opened this issue Sep 23, 2022 · 3 comments

Comments

@levino
Copy link

levino commented Sep 23, 2022

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:

  1. The emulator container will start with an empty folder. We then wait in our custom "firebase-tools" container for the firebase.json to show up.
  2. Once the firebase.json has shown up (because the main github action thread ran "checkout") we extract the location of the functions package.json and wait for it to show up.
  3. Once the functions package.json has shown up, we can finally start the emulators, as they would crash if the functions package.json is not present (btw: it suffices to put in {} to this package.json so the check is pretty pointless...). Here is the script for step 1. - 3. The functions package.json shows up once we have run our build step.
  4. 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:4000 which returns too early!
  5. We can run our test suite.

Is there something like http://localhost:4000/functions/health or so?

@levino
Copy link
Author

levino commented Sep 23, 2022

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.

@yuchenshi
Copy link
Member

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.

@hsuabina
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants