From 53d6926ac10db1c3d21ed18d8d528c885bd91171 Mon Sep 17 00:00:00 2001 From: Bryan Huhta Date: Tue, 24 May 2022 16:01:10 -0700 Subject: [PATCH 1/7] Put quickstart docker compose samples under examples/ Signed-off-by: Bryan Huhta --- examples/compose/crdb.yml | 46 ++++++++++++++++++++ examples/compose/memory.yml | 15 +++++++ examples/compose/mysql.yml | 36 ++++++++++++++++ examples/compose/postgres.yml | 36 ++++++++++++++++ examples/compose/spanner.yml | 48 +++++++++++++++++++++ examples/compose/spanner/Dockerfile.spanner | 11 +++++ examples/compose/spanner/spanner-init | 24 +++++++++++ 7 files changed, 216 insertions(+) create mode 100644 examples/compose/crdb.yml create mode 100644 examples/compose/memory.yml create mode 100644 examples/compose/mysql.yml create mode 100644 examples/compose/postgres.yml create mode 100644 examples/compose/spanner.yml create mode 100644 examples/compose/spanner/Dockerfile.spanner create mode 100755 examples/compose/spanner/spanner-init diff --git a/examples/compose/crdb.yml b/examples/compose/crdb.yml new file mode 100644 index 0000000000..354f94273a --- /dev/null +++ b/examples/compose/crdb.yml @@ -0,0 +1,46 @@ +--- +version: "3" + +services: + spicedb: + image: "authzed/spicedb" + command: "serve" + restart: "always" + ports: + - "8080:8080" + - "9090:9090" + - "50051:50051" + environment: + - "SPICEDB_GRPC_PRESHARED_KEY=foobar" + - "SPICEDB_DATASTORE_ENGINE=cockroachdb" + - "SPICEDB_DATASTORE_CONN_URI=postgresql://root:secret@database:26257/spicedb?sslmode=disable" + depends_on: + - "migrate" + + migrate: + image: "authzed/spicedb" + command: "migrate head" + restart: "on-failure" + environment: + - "SPICEDB_DATASTORE_ENGINE=cockroachdb" + - "SPICEDB_DATASTORE_CONN_URI=postgresql://root:secret@database:26257/spicedb?sslmode=disable" + depends_on: + - "init_database" + + init_database: + image: "cockroachdb/cockroach" + restart: "on-failure" + command: "sql --insecure -e 'CREATE DATABASE IF NOT EXISTS spicedb;'" + environment: + - "COCKROACH_HOST=database:26257" + depends_on: + - "database" + + database: + image: "cockroachdb/cockroach" + command: "start-single-node --insecure" + ports: + - "26257:26257" + - "8081:8080" # Using 8081 because 8080 is used by SpiceDB + environment: + - "POSTGRES_PASSWORD=secret" diff --git a/examples/compose/memory.yml b/examples/compose/memory.yml new file mode 100644 index 0000000000..9ec19f9401 --- /dev/null +++ b/examples/compose/memory.yml @@ -0,0 +1,15 @@ +--- +version: "3" + +services: + spicedb: + image: "authzed/spicedb" + command: "serve" + restart: "always" + ports: + - "8080:8080" + - "9090:9090" + - "50051:50051" + environment: + - "SPICEDB_GRPC_PRESHARED_KEY=foobar" + - "SPICEDB_DATASTORE_ENGINE=memory" diff --git a/examples/compose/mysql.yml b/examples/compose/mysql.yml new file mode 100644 index 0000000000..71c6a010bf --- /dev/null +++ b/examples/compose/mysql.yml @@ -0,0 +1,36 @@ +--- +version: "3" + +services: + spicedb: + image: "authzed/spicedb" + command: "serve" + restart: "always" + ports: + - "8080:8080" + - "9090:9090" + - "50051:50051" + environment: + - "SPICEDB_GRPC_PRESHARED_KEY=foobar" + - "SPICEDB_DATASTORE_ENGINE=mysql" + - "SPICEDB_DATASTORE_CONN_URI=root:secret@tcp(database:3306)/spicedb?parseTime=true" + depends_on: + - "migrate" + + migrate: + image: "authzed/spicedb" + command: "migrate head" + restart: "on-failure" + environment: + - "SPICEDB_DATASTORE_ENGINE=mysql" + - "SPICEDB_DATASTORE_CONN_URI=root:secret@tcp(database:3306)/spicedb?parseTime=true" + depends_on: + - "database" + + database: + image: "mysql" + ports: + - "3306:3306" + environment: + - "MYSQL_ROOT_PASSWORD=secret" + - "MYSQL_DATABASE=spicedb" diff --git a/examples/compose/postgres.yml b/examples/compose/postgres.yml new file mode 100644 index 0000000000..15f498b918 --- /dev/null +++ b/examples/compose/postgres.yml @@ -0,0 +1,36 @@ +--- +version: "3" + +services: + spicedb: + image: "authzed/spicedb" + command: "serve" + restart: "always" + ports: + - "8080:8080" + - "9090:9090" + - "50051:50051" + environment: + - "SPICEDB_GRPC_PRESHARED_KEY=foobar" + - "SPICEDB_DATASTORE_ENGINE=postgres" + - "SPICEDB_DATASTORE_CONN_URI=postgres://postgres:secret@database:5432/spicedb?sslmode=disable" + depends_on: + - "migrate" + + migrate: + image: "authzed/spicedb" + command: "migrate head" + restart: "on-failure" + environment: + - "SPICEDB_DATASTORE_ENGINE=postgres" + - "SPICEDB_DATASTORE_CONN_URI=postgres://postgres:secret@database:5432/spicedb?sslmode=disable" + depends_on: + - "database" + + database: + image: "postgres" + ports: + - "5432:5432" + environment: + - "POSTGRES_PASSWORD=secret" + - "POSTGRES_DB=spicedb" diff --git a/examples/compose/spanner.yml b/examples/compose/spanner.yml new file mode 100644 index 0000000000..8e529c38b8 --- /dev/null +++ b/examples/compose/spanner.yml @@ -0,0 +1,48 @@ +--- +version: "3" + +services: + spicedb: + image: "authzed/spicedb" + command: "serve" + restart: "always" + ports: + - "8080:8080" + - "9090:9090" + - "50051:50051" + environment: + - "SPICEDB_GRPC_PRESHARED_KEY=foobar" + - "SPICEDB_DATASTORE_ENGINE=spanner" + - "SPICEDB_DATASTORE_CONN_URI=projects/project-spicedb/instances/instance-spicedb/databases/spicedb" + - "SPANNER_EMULATOR_HOST=database:9010" + depends_on: + - "migrate" + + migrate: + image: "authzed/spicedb" + command: "migrate head" + restart: "on-failure" + environment: + - "SPICEDB_DATASTORE_ENGINE=spanner" + - "SPICEDB_DATASTORE_CONN_URI=projects/project-spicedb/instances/instance-spicedb/databases/spicedb" + - "SPANNER_EMULATOR_HOST=database:9010" + depends_on: + - "database_init" + + database_init: + build: + context: "./spanner" + dockerfile: "Dockerfile.spanner" + restart: "on-failure" + environment: + - "EMULATOR_HOST=http://database:9020/" + - "INSTANCE_NAME=instance-spicedb" + - "PROJECT_ID=project-spicedb" + depends_on: + - "database" + + database: + image: "gcr.io/cloud-spanner-emulator/emulator" + ports: + - "9010:9010" + - "9020:9020" diff --git a/examples/compose/spanner/Dockerfile.spanner b/examples/compose/spanner/Dockerfile.spanner new file mode 100644 index 0000000000..55f3c53504 --- /dev/null +++ b/examples/compose/spanner/Dockerfile.spanner @@ -0,0 +1,11 @@ +FROM google/cloud-sdk:slim + +RUN apt-get install -y google-cloud-sdk + +ENV EMULATOR_HOST="" +ENV INSTANCE_NAME="" +ENV PROJECT_ID="" + +COPY spanner-init . + +CMD ./spanner-init diff --git a/examples/compose/spanner/spanner-init b/examples/compose/spanner/spanner-init new file mode 100755 index 0000000000..304beb074d --- /dev/null +++ b/examples/compose/spanner/spanner-init @@ -0,0 +1,24 @@ +#!/bin/bash +#/ Sets up a spanner instance for SpiceDB. +#/ +#/ Expects the following environment variables: +#/ EMULATOR_HOST Host of the the Spanner emulator (i.e. http://localhost:9020/) +#/ WARN: This must have a trailing / +#/ INSTANCE_NAME Name of the Spanner instance +#/ PROJECT_ID Name of the project id + +# configure gcloud cli to connect to emulator +gcloud config set auth/disable_credentials true +gcloud config set project $PROJECT_ID +gcloud config set api_endpoint_overrides/spanner $EMULATOR_HOST + +# create spanner instance +gcloud spanner instances create $INSTANCE_NAME \ + --config=emulator-config \ + --description="Test Instance" \ + --nodes=1 + +gcloud config set spanner/instance $INSTANCE_NAME + +# create database +gcloud spanner databases create spicedb From 0eb911078e923a108d208c2139e00b2c3eaf2b6a Mon Sep 17 00:00:00 2001 From: Bryan Huhta Date: Tue, 31 May 2022 15:50:09 -0700 Subject: [PATCH 2/7] Include brief descriptions for example scripts Signed-off-by: Bryan Huhta --- examples/compose/crdb.yml | 22 ++++++++++++++++++++++ examples/compose/memory.yml | 8 ++++++++ examples/compose/mysql.yml | 17 +++++++++++++++++ examples/compose/postgres.yml | 17 +++++++++++++++++ examples/compose/spanner.yml | 27 +++++++++++++++++++++++++++ 5 files changed, 91 insertions(+) diff --git a/examples/compose/crdb.yml b/examples/compose/crdb.yml index 354f94273a..628471a11f 100644 --- a/examples/compose/crdb.yml +++ b/examples/compose/crdb.yml @@ -1,4 +1,26 @@ --- +# This runs SpiceDB, using CockroachDB as the storage engine. +# +# Once the database service is running, the init_database service will +# initialize CockroachDB for SpiceDB by creating the "spicedb" database. Next, +# the migrate service executes, running "spicedb migrate head" to migrate +# CockroachDB to the most current revision. After CockroachDB is intialized and +# migrated, the init_database and migrate services will stop. +# +# Note: CockroachDB is run using a single node configuration. +# +# SpiceDB settings: +# pre-shared key: foobar +# dashboard address: http://localhost:8080 +# metrics address: http://localhost:9090 +# grpc address: http://localhost:50051 +# +# CockroachDB settings: +# user: root +# password: secret +# port: 26257 +# dashboard address: http://localhost:8081 + version: "3" services: diff --git a/examples/compose/memory.yml b/examples/compose/memory.yml index 9ec19f9401..aa5a0f86f0 100644 --- a/examples/compose/memory.yml +++ b/examples/compose/memory.yml @@ -1,4 +1,12 @@ --- +# This runs SpiceDB, using an in-memory datastore as a the storage engine. +# +# SpiceDB settings: +# pre-shared key: foobar +# dashboard address: http://localhost:8080 +# metrics address: http://localhost:9090 +# grpc address: http://localhost:50051 + version: "3" services: diff --git a/examples/compose/mysql.yml b/examples/compose/mysql.yml index 71c6a010bf..79a3121b07 100644 --- a/examples/compose/mysql.yml +++ b/examples/compose/mysql.yml @@ -1,4 +1,21 @@ --- +# This runs SpiceDB, using MySQL as the storage engine. +# +# Once the database service is running, the migrate service executes, running +# "spicedb migrate head" to migrate MySQL to the most current revision. After +# MySQL is migrated, the migrate service will stop. +# +# SpiceDB settings: +# pre-shared key: foobar +# dashboard address: http://localhost:8080 +# metrics address: http://localhost:9090 +# grpc address: http://localhost:50051 +# +# MySQL settings: +# user: root +# password: secret +# port: 3306 + version: "3" services: diff --git a/examples/compose/postgres.yml b/examples/compose/postgres.yml index 15f498b918..61059619d9 100644 --- a/examples/compose/postgres.yml +++ b/examples/compose/postgres.yml @@ -1,4 +1,21 @@ --- +# This runs SpiceDB, using Postgres as the storage engine. +# +# Once the database service is running, the migrate service executes, running +# "spicedb migrate head" to migrate Postgres to the most current revision. After +# Postgres is migrated, the migrate service will stop. +# +# SpiceDB settings: +# pre-shared key: foobar +# dashboard address: http://localhost:8080 +# metrics address: http://localhost:9090 +# grpc address: http://localhost:50051 +# +# Postgres settings: +# user: postgres +# password: secret +# port: 5432 + version: "3" services: diff --git a/examples/compose/spanner.yml b/examples/compose/spanner.yml index 8e529c38b8..3d502a7a3f 100644 --- a/examples/compose/spanner.yml +++ b/examples/compose/spanner.yml @@ -1,4 +1,31 @@ --- +# This runs SpiceDB, using Spanner as the storage engine. +# +# In order to run Spanner locally, a Spanner emulator must be spun up. This is +# done by the database service. Once that is complete, the emulator must be +# initialized with a project, instance, and database. This is accomplished by +# the init_database service, which executes the init script found at +# spanner/spanner-init. This script configures the Spanner emulator with the a +# project, instance, and database. Finally, the migrate service executes, +# running "spicedb migrate head" to migrate Spanner to the most current +# revision. After Spanner is initialized and migrated, the init_database and +# migrate services will stop. +# +# Note: Spanner is run using a single node configuration. +# +# SpiceDB settings: +# pre-shared key: foobar +# dashboard address: http://localhost:8080 +# metrics address: http://localhost:9090 +# grpc address: http://localhost:50051 +# +# Spanner settings: +# project id: project-spicedb +# instance name: instance-spicedb +# database name: spicedb +# grpc port: 9010 +# http port: 9020 + version: "3" services: From e146cae47816f423a6ffe99148b552b0e214edf5 Mon Sep 17 00:00:00 2001 From: Bryan Huhta Date: Tue, 31 May 2022 15:53:38 -0700 Subject: [PATCH 3/7] Clarify SpiceDB will not have a schema Signed-off-by: Bryan Huhta --- examples/compose/crdb.yml | 3 ++- examples/compose/memory.yml | 1 + examples/compose/mysql.yml | 3 ++- examples/compose/postgres.yml | 3 ++- examples/compose/spanner.yml | 3 ++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/compose/crdb.yml b/examples/compose/crdb.yml index 628471a11f..d9ad53edec 100644 --- a/examples/compose/crdb.yml +++ b/examples/compose/crdb.yml @@ -1,5 +1,6 @@ --- -# This runs SpiceDB, using CockroachDB as the storage engine. +# This runs SpiceDB, using CockroachDB as the storage engine. SpiceDB will not +# have any schema written to it. # # Once the database service is running, the init_database service will # initialize CockroachDB for SpiceDB by creating the "spicedb" database. Next, diff --git a/examples/compose/memory.yml b/examples/compose/memory.yml index aa5a0f86f0..1bbda0097d 100644 --- a/examples/compose/memory.yml +++ b/examples/compose/memory.yml @@ -1,5 +1,6 @@ --- # This runs SpiceDB, using an in-memory datastore as a the storage engine. +# SpiceDB will not have any schema written to it. # # SpiceDB settings: # pre-shared key: foobar diff --git a/examples/compose/mysql.yml b/examples/compose/mysql.yml index 79a3121b07..72caf7e052 100644 --- a/examples/compose/mysql.yml +++ b/examples/compose/mysql.yml @@ -1,5 +1,6 @@ --- -# This runs SpiceDB, using MySQL as the storage engine. +# This runs SpiceDB, using MySQL as the storage engine. SpiceDB will not have +# any schema written to it. # # Once the database service is running, the migrate service executes, running # "spicedb migrate head" to migrate MySQL to the most current revision. After diff --git a/examples/compose/postgres.yml b/examples/compose/postgres.yml index 61059619d9..1a6b27171e 100644 --- a/examples/compose/postgres.yml +++ b/examples/compose/postgres.yml @@ -1,5 +1,6 @@ --- -# This runs SpiceDB, using Postgres as the storage engine. +# This runs SpiceDB, using Postgres as the storage engine. SpiceDB will not have +# any schema written to it. # # Once the database service is running, the migrate service executes, running # "spicedb migrate head" to migrate Postgres to the most current revision. After diff --git a/examples/compose/spanner.yml b/examples/compose/spanner.yml index 3d502a7a3f..43ca6de950 100644 --- a/examples/compose/spanner.yml +++ b/examples/compose/spanner.yml @@ -1,5 +1,6 @@ --- -# This runs SpiceDB, using Spanner as the storage engine. +# This runs SpiceDB, using Spanner as the storage engine. SpiceDB will not have +# any schema written to it. # # In order to run Spanner locally, a Spanner emulator must be spun up. This is # done by the database service. Once that is complete, the emulator must be From 478e16f47623935787116e7e57c5208ee100d0e5 Mon Sep 17 00:00:00 2001 From: Bryan Huhta Date: Tue, 31 May 2022 16:14:19 -0700 Subject: [PATCH 4/7] Add readme for quickstart examples Signed-off-by: Bryan Huhta --- examples/compose/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/compose/README.md diff --git a/examples/compose/README.md b/examples/compose/README.md new file mode 100644 index 0000000000..1d1e723e4d --- /dev/null +++ b/examples/compose/README.md @@ -0,0 +1,30 @@ +# Quickstart examples + +This directory contains a variety of quickstart examples to start SpiceDB with various storage engines. + +:warning: These examples are **not** production-ready and are provided purely for local testing only :warning: + + +## Usage + +To use a quickstart, run: + +``` +docker compose -f up +``` + +For example, running the Postgres quickstart: + +``` +docker compose -f postgres.yml up +``` + +Use `Ctrl+C` to stop the quickstart and use + +``` +docker compose -f postgres.yml down +``` + +to shut down the containers. + +> Note: Most quickstarts have configuration services in them to properly set up the storage engine. This means it may take a minute or so before the quickstart is ready to use. From d0ee919368320fe422f6ea32c7bdce7374155d2f Mon Sep 17 00:00:00 2001 From: Bryan Huhta Date: Tue, 31 May 2022 16:17:09 -0700 Subject: [PATCH 5/7] Fix markdown lints Signed-off-by: Bryan Huhta --- examples/compose/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/compose/README.md b/examples/compose/README.md index 1d1e723e4d..7ad654db9e 100644 --- a/examples/compose/README.md +++ b/examples/compose/README.md @@ -4,24 +4,23 @@ This directory contains a variety of quickstart examples to start SpiceDB with v :warning: These examples are **not** production-ready and are provided purely for local testing only :warning: - ## Usage To use a quickstart, run: -``` +```shell docker compose -f up ``` For example, running the Postgres quickstart: -``` +```shell docker compose -f postgres.yml up ``` Use `Ctrl+C` to stop the quickstart and use -``` +```shell docker compose -f postgres.yml down ``` From 18cc89c07bc7c6ff49b594ce408d1152d1e72ddd Mon Sep 17 00:00:00 2001 From: Bryan Huhta Date: Tue, 31 May 2022 16:21:45 -0700 Subject: [PATCH 6/7] Add list of available quickstarts Signed-off-by: Bryan Huhta --- examples/compose/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/compose/README.md b/examples/compose/README.md index 7ad654db9e..ecda7887f0 100644 --- a/examples/compose/README.md +++ b/examples/compose/README.md @@ -27,3 +27,11 @@ docker compose -f postgres.yml down to shut down the containers. > Note: Most quickstarts have configuration services in them to properly set up the storage engine. This means it may take a minute or so before the quickstart is ready to use. + +## Available quickstarts + +- [CockroachDB](crdb.yml) +- [Memory](memory.yml) +- [MySQL](mysql.yml) +- [Postgres](postgres.yml) +- [Spanner](spanner.yml) From e06d773b16de9c60e12213d8e259d19552c2cbd8 Mon Sep 17 00:00:00 2001 From: Bryan Huhta <32787160+bryanhuhta@users.noreply.github.com> Date: Tue, 31 May 2022 19:28:14 -0700 Subject: [PATCH 7/7] Use new and improved warning and note markdown Signed-off-by: Bryan Huhta --- examples/compose/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/compose/README.md b/examples/compose/README.md index ecda7887f0..a245f18021 100644 --- a/examples/compose/README.md +++ b/examples/compose/README.md @@ -2,7 +2,8 @@ This directory contains a variety of quickstart examples to start SpiceDB with various storage engines. -:warning: These examples are **not** production-ready and are provided purely for local testing only :warning: +> **Warning** +> These examples are **not** production-ready and are provided purely for local testing only. ## Usage @@ -26,7 +27,8 @@ docker compose -f postgres.yml down to shut down the containers. -> Note: Most quickstarts have configuration services in them to properly set up the storage engine. This means it may take a minute or so before the quickstart is ready to use. +> **Note** +> Most quickstarts have configuration services in them to properly set up the storage engine. This means it may take a minute or so before the quickstart is ready to use. ## Available quickstarts