Bundles the GCP Spanner CLI that gives you a convenient SQL prompt.
1.3K
This is a push of the Google Cloud utility to create an SQL prompt for Spanner in my local development environment.:
https://github.com/cloudspannerecosystem/spanner-cli
Here's how I use it locally with an emulator.
First, here are some environment variables I use to keep things organized as I run the different tools:
SPANNER_PROJECT_ID=test-project
SPANNER_INSTANCE_ID=test-instance
SPANNER_DATABASE_ID=test=database
SPANNER_GRPC_PORT=9010
SPANNER_GRPC_PORT=9020
SPANNER_CONTAINER_NAME=spanner-emulator
Setup the gcloud utility for the emulators:
gcloud config configurations create emulator || true
gcloud config set auth/disable_credentials true
gcloud config set project ${SPANNER_PROJECT_ID}
gcloud config set api_endpoint_overrides/spanner http://localhost:9020/
gcloud config set disable_color true
gcloud config set disable_prompts true
# Activate the configuration
gcloud config configurations activate emulator
Start the spanner emulator:
docker run -d \
--name ${SPANNER_CONTAINER_NAME} \
-p ${SPANNER_GRPC_PORT}:${SPANNER_GRPC_PORT} \
-p ${SPANNER_REST_PORT}:${SPANNER_REST_PORT} \
google/cloud-sdk \
gcloud beta emulators spanner start \
--host-port="0.0.0.0:${SPANNER_GRPC_PORT}" \
--rest-port=${SPANNER_REST_PORT} \
--project="${SPANNER_PROJECT_ID}"
Next, you'll have to create a spanner instance and database.
gcloud spanner instances create ${SPANNER_INSTANCE_ID} \
--config=emulator \
--description="Test Instance" \
--nodes=1
gcloud spanner databases create ${SPANNER_DATABASE_ID} \
--instance=${SPANNER_INSTANCE_ID}
Then, run the spanner-cli docker container with:
docker run --rm -it \
-e SPANNER_EMULATOR_HOST="localhost:${SPANNER_GRPC_PORT}" \
--network host \
ericzundel/spanner-cli:latest \
-i "${SPANNER_INSTANCE_ID}" \
-p "${SPANNER_PROJECT_ID}" \
-d "${SPANNER_DATABASE_ID}"
Content type
Image
Digest
sha256:6d3541ab1…
Size
19.9 MB
Last updated
10 months ago
docker pull ericzundel/spanner-cli