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

Set up Firebase Emulators #74

Merged
merged 8 commits into from
Jul 14, 2020
Merged

Set up Firebase Emulators #74

merged 8 commits into from
Jul 14, 2020

Conversation

floogulinc
Copy link
Member

@floogulinc floogulinc commented Jul 8, 2020

The major change here is that when you are running the dev server through ng serve it will be set to use the Firebase emulators for Firestore rather than the live production database. This was configured in the environment.ts and app.module.ts files. Authentication still happens against the live Firebase instance though.

We have setup a NPM script to run the emulator with settings that are most applicable to us currently. It is npm run firebase:emulator. This currently runs firebase emulators:start --only firestore --import firebase-test-data.

You should run the emulators at the same time as running ng serve. It provides a graphical web interface that is similar to the real Firebase dashboard. The command will tell you how to access it when you start the emulators.

We have setup a set of test data consisting of the demo-session and demo-round we already had in production. This was exported to the firebase-test-data directory and will be imported with the command described above. If you want to update this test data, make the changes you want in the local Firestore and run firebase emulators:export firebase-test-data.

floogulinc and others added 5 commits July 7, 2020 20:08
… app

Co-authored-by: KK Lamberty <lamberty@morris.umn.edu>
This adds a small set of test data, "demo-session" and "demo-round" that matches what we have in production Firestore at the moment.
It can be used with the `--import` parameter when running the Firebase emulators. This also creates a npm script `npm run firebase:emulator` that starts the emulator for just Firestore and imports the test data.

Co-authored-by: KK Lamberty <lamberty@morris.umn.edu>
Co-authored-by: KK Lamberty <lamberty@morris.umn.edu>
@vercel
Copy link

vercel bot commented Jul 8, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/mn-pollinators/buzz-about/56n4znlbv
✅ Preview: https://buzz-about-git-firebase-emulator.mn-pollinators.vercel.app

@floogulinc floogulinc marked this pull request as draft July 8, 2020 01:21
@floogulinc floogulinc marked this pull request as ready for review July 8, 2020 01:27
@helloworld12321 helloworld12321 added this to In progress in Buzz About via automation Jul 8, 2020
@helloworld12321 helloworld12321 moved this from In progress to Review in progress in Buzz About Jul 8, 2020
Copy link
Member

@helloworld12321 helloworld12321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, gosh, it looks like you've got a wonky compatibility issue here!

So, you know those those test-data binary files y'all made, right? It seems like, inside them, Firebase is storing some file paths—but those paths use backslashes as a path separator 😛

/home/joemoonan/Documents/Pollinators/buzz-about/firebase-test-data/firestore_export/all_namespaces\all_kinds\all_namespaces_all_kinds.export_metadata (No such file or directory)

What happens:

When you try to run npm firebase:emulate on a Unix system, the script dies with the following output:

joemoonan buzz-about $ npm run firebase:emulator

> buzz-about@0.0.0 firebase:emulator /home/joemoonan/Documents/Pollinators/buzz-about
> firebase emulators:start --only firestore --import firebase-test-data

i  emulators: Starting emulators: firestore
i  firestore: Importing data from /home/joemoonan/Documents/Pollinators/buzz-about/firebase-test-data/firestore_export/firestore_export.overall_export_metadata
i  firestore: Firestore Emulator logging to firestore-debug.log

Error: firestore: Firestore Emulator has exited with code: 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! buzz-about@0.0.0 firebase:emulator: `firebase emulators:start --only firestore --import firebase-test-data`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the buzz-about@0.0.0 firebase:emulator script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/joemoonan/.npm/_logs/2020-07-08T05_02_28_016Z-debug.log

Funnily enough, the firebase emulator doesn't even exit cleanly; at the end of this command, it stays running in the background. (You can stop the background instance by running firebase emulators:start --only firestore to start another instance of the emulator, and then pressing ^C to stop all emulators.)

I've attached the two log files that were generated, firestore-debug.log and 2020-07-08T05_02_28_016Z-debug.log, below. The former is where I found the file path quoted above; the latter doesn't seem to have anything useful in it; it's just npm saying "Oh, the humanity!".

Other salient information:

When I try to make my own test-data binary files on Unix, I can import them just fine; because of this, I bet that the backslashes occur when you export the data on Windows. (Whether there's a way to get Windows to use forward-slashes, I have no idea 🤷🏻‍♂️)

Sorry to be the bearer of bad news :-(

Log files:

@floogulinc
Copy link
Member Author

Very interesting @helloworld12321. Looks like when you export on Windows it uses \ in some files. See upstream issue firebase/firebase-tools#2421.

The solution at the moment may be that we have to export on *nix (or maybe we can get away with manually changing the paths). As far as I know Windows actually handles both / and \ as path separators so using / may just work for Windows as well.

@helloworld12321
Copy link
Member

helloworld12321 commented Jul 9, 2020

Ooh, nice find on that issue!

I wonder, would it make sense to populate the database programmatically as part of the test suite? (That also would give us a degree of flexibility—for example, we'd be able to test the teacher-side with & without a previous session that they could resume.)

If not, though, then only exporting from Unix seems like a reasonable stopgap until the upstream folks fix this issue. 🙂

@floogulinc
Copy link
Member Author

Yeah for testing the plan indeed is to setup stuff in the database during the test. We just need this basic demo data for local development at the moment. Once we have session and round creation though we won't need to be seeding it.

Co-authored-by: Joe Walbran <walbr037@morris.umn.edu>
@floogulinc
Copy link
Member Author

So for the moment if you are using Windows and export new data, please don't commit the changed firebase-test-data\firestore_export\firestore_export.overall_export_metadata file.

It was a string instead of a number
Buzz About automation moved this from Review in progress to Reviewer approved Jul 9, 2020
Copy link
Member

@helloworld12321 helloworld12321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, everything looks good, thanks!

Copy link
Contributor

@ErikRauer ErikRauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have any issues running the emulator

@helloworld12321 helloworld12321 moved this from Reviewer approved to Review in progress in Buzz About Jul 13, 2020
Buzz About automation moved this from Review in progress to Reviewer approved Jul 14, 2020
Copy link
Contributor

@audreylemeur audreylemeur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working for me.

@floogulinc floogulinc merged commit 5db51ee into master Jul 14, 2020
Buzz About automation moved this from Reviewer approved to Done Jul 14, 2020
@UtkarshKr007 UtkarshKr007 deleted the firebase-emulator branch August 7, 2020 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Buzz About
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants