blob: 09ebf791d7cf4f27e0be4b3da2263fae8c0b5309 [file] [log] [blame] [edit]
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
TMPDIR="${TMPDIR:-/tmp}"
nohup bazelisk run --config=mayberemote //scripts/run_emulators "$@" > ${TMPDIR}/cloud_emulators.log &
cmd="$1"
shift
if [ "$cmd" == "start" ]; then
sleep 20 # Give the emulators time to start up before exiting.
read -p "Do you want to also start PGAdapter for Spanner emulator? [Y/n] " -n 1 -r
echo # Move to a new line
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
echo "Starting PGAdapter..."
sudo docker ps -q | xargs -r sudo docker rm -vf
sudo docker run -d -p 5432:5432 gcr.io/cloud-spanner-pg-adapter/pgadapter-emulator
fi
# The ports below should be kept in sync with run_emulators.go.
echo "Emulators started. Set environment variables as follows:"
cat << EOF
export DATASTORE_EMULATOR_HOST=localhost:8891
export BIGTABLE_EMULATOR_HOST=localhost:8892
export PUBSUB_EMULATOR_HOST=localhost:8893
export FIRESTORE_EMULATOR_HOST=localhost:8894
export COCKROACHDB_EMULATOR_HOST=localhost:8895
EOF
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
cat << EOF
export PGADAPTER_HOST=localhost:5432
export SPANNER_EMULATOR_HOST=localhost:9010
EOF
fi
elif [ "$cmd" == "stop" ]; then
echo "Emulators stopped. Unset environment variables as follows:"
cat << EOF
export DATASTORE_EMULATOR_HOST=
export BIGTABLE_EMULATOR_HOST=
export PUBSUB_EMULATOR_HOST=
export FIRESTORE_EMULATOR_HOST=
export COCKROACHDB_EMULATOR_HOST=
export PGADAPTER_HOST=
export SPANNER_EMULATOR_HOST=
EOF
if [ "$1" == "--dump-logs" ]; then
echo "Emulator logs:"
cat ${TMPDIR}/cloud_emulators.log
fi
fi