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

Enable completely offline Duelyst development via Firebase Emulator instrumentation #278

Open
avisaiwe opened this issue Feb 3, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@avisaiwe
Copy link

avisaiwe commented Feb 3, 2023

I was able to get the firebase emulator (realtime db and auth) up and running and discovered they can be made to cycle while persisting data. Was able to instrument the server/lib/duelyst_firebase_module.coffee file to use the emulators for auth and database read/write. Got as far as able to create a new user and it's details updated within the emulated db, but couldn't progress farther due to how old the firebase-web module is

Unsure if there is a way to instrument it to use a local emulator (seems not as it'll error if not provided a firebaseio.com url). I tried beautifying and disabling as much of the obfuscated code as I could to bypass the checks, but alas still nothing. I checked with firebase-web v8 and was able to connect to the emulator and read/write.

To get the final piece working and potentially have 100% offline duelyst development would either require

  1. someone much more skillful at javascript to modify the firebase v2 module to prime and communicate with the emulator, I believe it'll accept any unsigned token
  2. hope someone knows or has the documentation on how to hook up the emulator to firebase-web v2 (I've tried wayback machine to no success either, only goes back to 2016 for the emulator instrumentation logic)
  3. implement issue #192 to update the frontend logic to firebase v8 or v9

Documentation on starting up the emulators and various flags
https://firebase.google.com/docs/emulator-suite/install_and_configure#startup

Command I used to start up the emulator with persistency
note: emulator has a logic that if project key starts with demo- prefix will ensure no calls accidentally reach to production instances, all calls will be only local
firebase emulators:start --export-on-exit=./fire_emu_data --project demo-foobaryst --import=./fire_emu_data

Modifications done to instrument firebase-admin for emulator usage
https://firebase.google.com/docs/emulator-suite/connect_auth#admin_sdks
for instrumenting the firebase-admin backend portion that Duelyst uses, all that is needed is to add the emulators url to a local environment variable and it'll do the rest. I hard coded it just for testing purposes, probably best practice would be to update the dotenv declaration.

Duelyst_firebase_module.coffee modifications for instrumentation
https://github.com/open-duelyst/duelyst/blob/main/server/lib/duelyst_firebase_module.coffee
note: I just added the env variable at the top of the file (before firebase module was loaded) and mocked in a dummy token for ease of testing

line 1:
process.env.FIREBASE_AUTH_EMULATOR_HOST="192.168.33.3:9099"

any line with a firebaseServiceAccount reference
firebaseServiceAccount = {
  project_id: "demo-foobaryst",
  client_email: "[email protected]",
  private_key: "cHJpdmF0ZWtleQo=",
}

line 82:
//with firebaseDBEmuUrl just the ip:port to the database, the first line/env set was ip:port for the auth
app = firebaseAdmin.initializeApp({databaseURL: firebaseDbEmuUrl}, firebaseDbEmuUrl)


Create user invocation success, but just hangs infinitely due to old firebase-web version
image

Snippet of Firebase Emulator UI showing Duelyst backend creating the user and initial boss rotation data
image

@avisaiwe avisaiwe added the enhancement New feature or request label Feb 3, 2023
@dillfrescott
Copy link

How neat!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants