-
-
Save kylebradshaw/c897f4b28c2baa2a57625f3210dd976d to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
# seed-storage | |
# ============ | |
# Seed an existing firebase cloud storage emulator instance. Run it inside your | |
# project's firebase folder, ie: ./seed-storage.sh <project-name> <dest-folder> | |
name=firebase_export # firebase export dir name | |
project=$1 # project name | |
root=$2 # export root path | |
uri=gs://$project.appspot.com/$name # cloud storage URI | |
trap "kill 0" EXIT | |
echo '[1/5] Preparing local/remote filesystems for seeding…' | |
# check if a remote file exists and wipe parent dir if needed | |
gsutil -q stat $uri/$name.overall_export_metadata | |
[ $? -eq 0 ] && gsutil -q rm -f ${uri}** | |
# create root path if needed | |
mkdir -p $root | |
echo '[2/5] Starting emulators in the background…' | |
# start emulator if port isn't open | |
lsof -i TCP:4000 &> /dev/null | |
[ $? -eq 0 ] || screen -S $name -d -m firebase emulators:start & | |
# wait until server is detected | |
lsof -i TCP:4000 &> /dev/null | |
while [ $? -ne 0 ]; do sleep 5; done | |
# exit on any error from now on | |
trap "exit" INT ERR | |
# create importable file/dir structure | |
firebase --non-interactive --project $project emulators:export --force $root &> /dev/null | |
echo "[3/5] Exporting firestore snapshot to $uri" | |
gcloud --verbosity=none firestore export $uri &> /dev/null | |
echo "[4/5] Downloading exported data to $root" | |
gsutil -q cp -r $uri $root | |
echo '[5/5] Cleaning up…' | |
screen -S $name -X quit | |
echo '\nDone! Use the following command to run the emulator:' | |
echo "firebase emulators:start --import=$root" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment