diff --git a/pkg/files/docker/spanner.Dockerfile b/pkg/files/docker/spanner.Dockerfile new file mode 100644 index 0000000..c820c76 --- /dev/null +++ b/pkg/files/docker/spanner.Dockerfile @@ -0,0 +1,10 @@ +FROM img.dev.storj.io/storjup/base:20240509-1 AS binaries + +FROM google/cloud-sdk:492.0.0-slim AS final +RUN apt-get install -y google-cloud-cli-spanner-emulator + +ADD pkg/recipe/startspanner.sh /var/lib/storj/startspanner.sh +COPY --from=binaries /var/lib/storj/go/bin /var/lib/storj/go/bin + +ENTRYPOINT ["/var/lib/storj/startspanner.sh"] +ENV PATH=$PATH:/var/lib/storj/go/bin diff --git a/pkg/recipe/default.go b/pkg/recipe/default.go index dd560b0..d29d72d 100644 --- a/pkg/recipe/default.go +++ b/pkg/recipe/default.go @@ -16,6 +16,9 @@ var db []byte //go:embed postgres.yaml var postgres []byte +//go:embed spanner.yaml +var spanner []byte + //go:embed edge.yaml var edge []byte @@ -56,6 +59,7 @@ var Defaults = map[string][]byte{ "satellite-admin": satelliteAdmin, "db": db, "postgres": postgres, + "spanner": spanner, "edge": edge, "tracing": tracing, "billing": billing, diff --git a/pkg/recipe/spanner.yaml b/pkg/recipe/spanner.yaml new file mode 100644 index 0000000..e127ffc --- /dev/null +++ b/pkg/recipe/spanner.yaml @@ -0,0 +1,22 @@ +name: spanner +description: spanner DB. +add: + - name: spanner + image: img.dev.storj.io/storjup/spanner:492.0.0 + port: + - name: gRPC + description: Spanner gRPC port + target: 9010 + - name: REST + description: Spanner REST port + target: 9020 + environment: + PROJECT_ID: test-project + INSTANCE_NAME: test-instance + SPANNER_EMULATOR_URL: http://localhost:9020/ +modify: + - match: + name: satellite-api,satellite-core,satellite-admin + config: + SPANNER_EMULATOR_HOST: 'spanner:9010' + STORJ_METAINFO_DATABASE_URL: "spanner://projects/test-project/instances/test-instance/databases/metainfo" diff --git a/pkg/recipe/startspanner.sh b/pkg/recipe/startspanner.sh new file mode 100644 index 0000000..f368b12 --- /dev/null +++ b/pkg/recipe/startspanner.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -xem +echo "Starting Spanner dev container" + +gcloud emulators spanner start --host-port=0.0.0.0:9010& +gcloud config set disable_prompts true +gcloud config configurations create emulator +gcloud config set auth/disable_credentials true +gcloud config set project "${PROJECT_ID}" +gcloud config set api_endpoint_overrides/spanner "${SPANNER_EMULATOR_URL}" +gcloud spanner instances create "${INSTANCE_NAME}" --config=emulator-config --description=Emulator --nodes=1 + +#TODO: find a more flexible way to create the databases +gcloud spanner databases create master --instance="${INSTANCE_NAME}" +gcloud spanner databases create metainfo --instance="${INSTANCE_NAME}" + +fg %1