Last active
September 30, 2022 04:10
-
-
Save danahartweg/72600e0d30ae54290bf4deb197400ee9 to your computer and use it in GitHub Desktop.
Running the firestore emulator in a CI environment without IPv6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
EMULATOR="cloud-firestore-emulator" | |
EMULATOR_TARGET=$(find ~/.cache/firebase/emulators/ -type f -name "$EMULATOR*.jar" | sort -r | head -n1) | |
if [ -z "$EMULATOR_TARGET" ]; then | |
echo "Could not find the firestore emulator. Ending test run." | |
exit 1 | |
fi | |
# I've found that the java process is not always killed properly, | |
# causing issues on subsequent runs... so let's clean things up when we're done (or have errored) | |
killEmulatorPid() | |
{ | |
EMULATOR_PID=$(pgrep -f "$EMULATOR") | |
if ! [ -z "$EMULATOR_PID" ]; then | |
kill -9 "$EMULATOR_PID" | |
fi | |
} | |
java -jar "$EMULATOR_TARGET" --host=127.0.0.1 --port=8080 > /dev/null 2> firestore-emulator.log & | |
RETRIES=0 | |
RETRY_LIMIT=10 | |
while [ $RETRIES -lt $RETRY_LIMIT ]; do | |
sleep 1 | |
echo "Pinging firestore emulator" | |
if nc -z localhost 8080; then | |
break | |
fi | |
let RETRIES+=1 | |
if [ $RETRIES -ge $RETRY_LIMIT ]; then | |
echo "Could not find the firestore emulator. Ending test run." | |
killEmulatorPid | |
exit 1 | |
fi | |
done | |
yarn test | |
echo "End of test run. Cleaning up the firestore emulator." | |
killEmulatorPid |
Hi @danahartweg,
Thanks for this script. From what I can tell, it assumes that you already have the
cloud-firestore-emulator
available in the~/.cache/firebase/emulators/
directory - is that correct?
Yes, this comes from already setting up the simulator on building the Docker image. E.g. via RUN firebase setup:emulators:firestore
@pschneider your answer is spot on, thanks! @jperasmus thanks for your patience, I'm not entirely sure how I missed your comment from so long ago.
Thanks, got it working in the end. AFAIK, GitHub doesn't do notifications (or didn't at one point) for comments on Gists.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @danahartweg,
Thanks for this script. From what I can tell, it assumes that you already have the
cloud-firestore-emulator
available in the~/.cache/firebase/emulators/
directory - is that correct?