-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create driver and migrations for spanner (psql) (#306)
* Create driver and migrations for spanner (psql) - [x] create seperate migration directories for spanner SQL files - [x] create `pgx` driver to use spanner-pg-adapter - [x] create additional config directory to configure `pgx` driver - [x] create docker compose file for building dev containers with spanener and spanner-pg-adapter Signed-off-by: Bailin He <bahe@equinix.com> * renamed enums Signed-off-by: Bailin He <bahe@equinix.com> * use spanner `.env` file Signed-off-by: Bailin He <bahe@equinix.com> * update helm chart Signed-off-by: Bailin He <bahe@equinix.com> * fix typo `db.engine` Signed-off-by: Bailin He <bahe@equinix.com> --------- Signed-off-by: Bailin He <bahe@equinix.com>
- Loading branch information
Showing
34 changed files
with
616 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
networks: | ||
infradev: | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
VARIANT: 1.23-bullseye | ||
NODE_VERSION: "none" | ||
command: sleep infinity | ||
# uncomment along with bind volume to use SSH for dev container access | ||
# ports: | ||
# - "127.0.0.1:2224:2222" | ||
env_file: | ||
- spanner.env | ||
volumes: | ||
- ./nsc:/nsc | ||
- ./nats:/nats | ||
- ..:/workspace:cached | ||
# - type: bind | ||
# source: ~/.ssh/authorized_keys | ||
# target: /home/vscode/.ssh/authorized_keys | ||
# read_only: true | ||
networks: | ||
- infradev | ||
# Use "forwardPorts" in **devcontainer.json** to forward a port locally. | ||
# (Adding the "ports" property to this file will not forward from a Codespace.) | ||
|
||
# DB | ||
spanner: | ||
image: gcr.io/cloud-spanner-emulator/emulator | ||
networks: | ||
- infradev | ||
ports: | ||
- "9010:9010" | ||
- "9020:9020" | ||
|
||
spanner-pg: | ||
image: gcr.io/cloud-spanner-pg-adapter/pgadapter | ||
command: | ||
- "-p test-project" | ||
- "-i test-instance" | ||
- "-r autoConfigEmulator=true" | ||
- "-e spanner:9010" | ||
- "-c \"\"" | ||
- "-x" | ||
- -ddl=AutocommitExplicitTransaction | ||
ports: | ||
- "5432:5432" | ||
depends_on: | ||
- spanner | ||
networks: | ||
- infradev | ||
|
||
create-databases-pg: | ||
image: postgres:13.4 | ||
restart: on-failure:5 | ||
command: | | ||
psql -h spanner-pg -c 'CREATE DATABASE permissionsapi;' | ||
depends_on: | ||
- spanner-pg | ||
networks: | ||
- infradev | ||
|
||
create-databases-spanner: | ||
image: alpine/curl | ||
restart: on-failure:5 | ||
command: | | ||
curl -X POST \ | ||
http://spanner:9020/v1/projects/test-project/instances/test-instance/databases \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"createStatement": "CREATE DATABASE spicedb", | ||
"databaseDialect": "GOOGLE_STANDARD_SQL" | ||
}' | ||
depends_on: | ||
create-databases-pg: | ||
condition: service_completed_successfully | ||
networks: | ||
- infradev | ||
|
||
create-goose-table: | ||
image: postgres:13.4 | ||
depends_on: | ||
create-databases-pg: | ||
condition: service_completed_successfully | ||
restart: on-failure:5 | ||
networks: | ||
- infradev | ||
command: | | ||
psql -h spanner-pg -d projects/test-project/instances/test-instance/databases/permissionsapi \ | ||
-c \ | ||
'CREATE TABLE IF NOT EXISTS public.goose_db_version ( | ||
id BIGINT NOT NULL DEFAULT (extract(epoch from CURRENT_TIMESTAMP)*1000)::bigint, | ||
version_id BIGINT NOT NULL, | ||
is_applied BOOLEAN NOT NULL, | ||
tstamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY (id) | ||
); | ||
INSERT INTO goose_db_version (version_id, is_applied) VALUES (0, true);' | ||
migrate_spicedb: | ||
image: authzed/spicedb:v1.38.1 | ||
command: datastore migrate head | ||
restart: on-failure:5 | ||
env_file: | ||
- spanner.env | ||
depends_on: | ||
create-databases-pg: | ||
condition: service_completed_successfully | ||
networks: | ||
- infradev | ||
|
||
spicedb: | ||
image: authzed/spicedb:v1.38.1 | ||
command: serve | ||
restart: unless-stopped | ||
env_file: | ||
- spanner.env | ||
depends_on: | ||
migrate_spicedb: | ||
condition: service_completed_successfully | ||
ports: | ||
- 50051:50051 | ||
networks: | ||
- infradev | ||
|
||
nats-init: | ||
image: natsio/nats-box | ||
environment: | ||
- NSC_HOME=/nsc | ||
volumes: | ||
- ./nsc:/nsc | ||
- ./nats:/nats | ||
- ./scripts:/scripts | ||
command: | ||
- /scripts/nats_init.sh | ||
|
||
nats: | ||
image: 'nats:alpine' | ||
depends_on: | ||
- nats-init | ||
command: | ||
- -c | ||
- '/etc/nats/nats-server.conf' | ||
- -D | ||
volumes: | ||
- ./nats/:/etc/nats | ||
restart: unless-stopped | ||
networks: | ||
- infradev | ||
|
||
jaeger: | ||
image: jaegertracing/all-in-one:1.60.0 | ||
environment: | ||
- COLLECTOR_OTLP_ENABLED=true | ||
ports: | ||
- 16688:16686 | ||
networks: | ||
- infradev | ||
|
||
mock-oauth2-server: | ||
image: ghcr.io/navikt/mock-oauth2-server:2.1.10 | ||
networks: | ||
- infradev | ||
environment: | ||
- PORT=8081 | ||
ports: | ||
- 8081:8081 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# spicedb container config | ||
SPICEDB_GRPC_PRESHARED_KEY=infradev | ||
SPICEDB_DATASTORE_ENGINE=spanner | ||
SPICEDB_DATASTORE_CONN_URI='projects/test-project/instances/test-instance/databases/spicedb' | ||
SPICEDB_DATASTORE_SPANNER_EMULATOR_HOST=spanner:9010 | ||
SPICEDB_LOG_LEVEL=info | ||
SPICEDB_LOG_FORMAT=console | ||
SPICEDB_OTEL_PROVIDER=jaeger | ||
SPICEDB_OTEL_INSECURE=true | ||
SPICEDB_OTEL_ENDPOINT=http://app:14268/api/traces | ||
SPICEDB_TESTING_ONLY_SCHEMA_ADDITIVE_WRITES=true | ||
|
||
# zed CLI tool config | ||
ZED_ENDPOINT=spicedb:50051 | ||
ZED_INSECURE=true | ||
ZED_TOKEN=infradev | ||
|
||
PERMISSIONSAPI_DB_DRIVER=postgres | ||
PERMISSIONSAPI_SPANNER_URI="postgresql://spanner-pg:5432/permissionsapi?sslmode=disable" | ||
PERMISSIONSAPI_TRACING_ENABLED=true | ||
PERMISSIONSAPI_TRACING_PROVIDER=otlpgrpc | ||
PERMISSIONSAPI_TRACING_OTLP_ENDPOINT=jaeger:4317 | ||
PERMISSIONSAPI_TRACING_OTLP_INSECURE=true | ||
PERMISSIONSAPI_SPICEDB_ENDPOINT=spicedb:50051 | ||
PERMISSIONSAPI_SPICEDB_KEY=infradev | ||
PERMISSIONSAPI_SPICEDB_INSECURE=true | ||
|
||
PERMISSIONSAPI_PUBSUB_NAME=permissionsapi | ||
PERMISSIONSAPI_PUBSUB_CREDENTIALS="/tmp/user.creds" | ||
PERMISSIONSAPI_PUBSUB_SERVER="nats://nats:4222" | ||
PERMISSIONSAPI_PUBSUB_STREAM="permissionsapi" | ||
PERMISSIONSAPI_PUBSUB_PREFIX="com.infratographer.events" | ||
|
||
NATS_URL="nats://nats:4222" | ||
NATS_CREDS="/tmp/user.creds" | ||
|
||
NKEYS_PATH="/workspace/.devcontainer/nsc/nkeys" | ||
NSC_HOME="/workspace/.devcontainer/nsc/nats" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.