Skip to content

Commit

Permalink
updates to allow for testing services with notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytheleg committed Feb 12, 2025
1 parent 35ea8d6 commit 8387bb7
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ spicedb-up:
./spicedb/start-spicedb.sh
.PHONY: spicedb-up

# uses alternative postgres port to avoid conflicts
spicedb-alt-up:
./spicedb/start-spicedb-alt-port.sh
.PHONY: spicedb-alt-up

relations-api-up:
./spicedb/start-relations-api.sh
.PHONY: relations-api-up
Expand Down
76 changes: 76 additions & 0 deletions docker-compose-alt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
services:
relations-api:
image: "quay.io/cloudservices/kessel-relations:latest"
environment:
- "SPICEDB_PRESHARED=${SPICEDB_GRPC_PRESHARED_KEY}"
- "SPICEDB_SCHEMA_FILE=/schema_file"
# - "SPICEDB_PRESHARED_FILE=/run/secrets/spicedb_pre_shared"
- "SPICEDB_ENDPOINT=spicedb:50051"
build:
dockerfile: Dockerfile
profiles: ["relations-api"]
secrets:
- spicedb_pre_shared
configs:
- schema_file
restart: "always"
ports:
- "8000:8000"
- "9000:9000"
networks:
- kessel

spicedb:
image: "authzed/spicedb"
command: "serve"
restart: "always"
ports:
- "8080:8080"
- "9090:9090"
- "50051:50051"
environment:
- "SPICEDB_GRPC_PRESHARED_KEY=${SPICEDB_GRPC_PRESHARED_KEY}"
- "SPICEDB_DATASTORE_ENGINE=postgres"
- "SPICEDB_DATASTORE_CONN_URI=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5433/spicedb?sslmode=disable"
depends_on:
- "migrate"
networks:
- kessel

migrate:
image: "authzed/spicedb"
command: "migrate head"
restart: "on-failure"
environment:
- "SPICEDB_DATASTORE_ENGINE=postgres"
- "SPICEDB_DATASTORE_CONN_URI=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5433/spicedb?sslmode=disable"
depends_on:
- "database"
networks:
- kessel

database:
image: "postgres"
command: -c track_commit_timestamp=on -p 5433
ports:
- "5433:5433"
environment:
- "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}"
- "POSTGRES_DB=${POSTGRES_DBNAME}"
networks:
- kessel

configs:
spicedb_pre_shared:
environment: "SPICEDB_GRPC_PRESHARED_KEY"
schema_file:
file: deploy/schema.zed

secrets:
spicedb_pre_shared:
file: ./.secrets/local-spicedb-secret

networks:
kessel:
name: kessel
external: true
43 changes: 43 additions & 0 deletions docs/local-testing-w-notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Running Notifications + Relations + Inventory using Local Built Binaries

### Running Relations:
```shell
# Start up SpiceDB Alt -- uses a different postgres port to avoid conflicts with notifications
make spicedb-alt-up

# Start relations
make run
```

### Running Inventory:
The process to run Inventory locally can be found in Inventory API's [README](https://github.com/project-kessel/inventory-api?tab=readme-ov-file#kessel-inventory--kessel-relations-using-built-binaries)

### Running Notifications

> NOTE: During the clean and install step tests are run that may not work if you do not have Docker -- YMMV
```shell
# Spin up the Notifications DB
podman run --name notifications_db --detach -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=notifications -p 5432:5432 docker.io/postgres:latest -c log_statement=all

# Clean, Compile, Test, and Install
./mvnw clean install

# OR to skip tests (takes about 15 mins)
./mvnw clean install -Dmaven.test.skip

# Run the Notifications Service
./mvnw clean quarkus:dev -Dnotifications.use-default-template=true -Dnotifications.kessel-inventory.enabled=true -Dnotifications.kessel-relations.enabled=true -pl :notifications-backend
```

### Cleanup!
```shell
# To kill notifications, enter `q` in the running window to shut it down
# To kill inventory and relations, use whatever fun killing technique you like!

# Teardown SpiceDB
make spicedb-down

# Teardown Notifications DB
podman stop notifications_db && podman rm notifications_db
```
7 changes: 7 additions & 0 deletions spicedb/start-spicedb-alt-port.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
# Function to check if a command is available
source ./spicedb/check_docker_podman.sh
NETWORK_CHECK=$(${DOCKER} network ls --filter name=kessel --format json)
if [[ -z "${NETWORK_CHECK}" || "${NETWORK_CHECK}" == "[]" ]]; then ${DOCKER} network create kessel; fi
${DOCKER} compose --env-file ./spicedb/.env -f ./docker-compose-alt.yaml up -d

0 comments on commit 8387bb7

Please sign in to comment.