Sample application displaying Cloud Spanner and GKE integration.
This application is a simple registry of singers, which uses Cloud Spanner as a database. A screenshot of the application can be seen below:
You can run the application directly from your machine by following the instructions below.
To run the application locally you should have nodejs
and npm
installed.
You should configure your Cloud Spanner instance id and database id in the code. These can be configured through the following environment variables respectively: CLOUD_SPANNER_INSTANCE
and CLOUD_SPANNER_DATABASE
. Alternatively you can hardcode the values by modifying the src/server.js file.
You should have set up authentication and authorization for your Cloud Spanner instance and database. You can follow the Cloud Spanner getting started guide for more information.
# Builds the application and install dependencies
npm install && npm run build
npm start
You should see the web server available at port 8080
by default.
You can also run the application using a Docker image.
You will need to have your credentials exposed to the docker container, so that it can use Cloud Spanner. You can follow the Cloud Spanner getting started guide for more information.
Build the docker image.
docker build . -t sample-app
Run the docker image. Make sure to replace your GCP project id, Cloud Spanner instance and database name in the command below if you don't have the environment variables used set.
docker run \
-v "$HOME/.config/gcloud:/gcp/config:ro" \
--env GOOGLE_APPLICATION_CREDENTIALS=/gcp/config/application_default_credentials.json \
--env GOOGLE_CLOUD_PROJECT_ID=$GOOGLE_CLOUD_PROJECT_ID \
--env CLOUD_SPANNER_INSTANCE=$CLOUD_SPANNER_INSTANCE \
--env CLOUD_SPANNER_DATABASE=$CLOUD_SPANNER_DATABASE \
-p 8080:8080 \
sample-app
You should see the web server available at port 8080
by default.