Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates to allow for testing services with notifications #371

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 16 additions & 2 deletions docs/ephemeral-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ You'll need:
1) Bonfire
2) Podman/Docker
3) Credentials to login to Quay.io (can be your personal credentials or a [Robot Account](https://docs.quay.io/glossary/robot-accounts.html) if desired)
4) A public Quay repo to push your image to

**tl;dr**
1) Make your changes
Expand Down Expand Up @@ -65,11 +66,24 @@ In the output you'll see where bonfire detects your settings for this app and co

## Building Container images for testing

Building your own container image to test with is easy, you just need a public quay repo to push to and consume from
Building your own container image to test with is easy, you just need a **public** quay repo to push to and consume from. These images are designed to be consumed in a cluster.

> Note: If your Quay repo is not public, the cluster will not be able to pull the image. By default, when you push an image to Quay for the first time, it will create the repo for you, but it is set to private by default. This can be changed by navigating to the repo in Quay --> Settings --> Repository Visibility --> Make Public

> Another Note: The process is slightly different for Mac to encompass those using ARM laptops. Using the `build-push-minimal` make target ensures the image is built for Linux/AMD64 to ensure it can run on clusters but may not be ideal for running locally for those on ARM systems.


**To build the image on Linux:**
1) Set the image repo for where the image should be pushed to: `export IMAGE=quay.io/my-repo/relations-api`
2) Set your Quay.io credentials so your container engine can login to push: `export QUAY_USER=your-username; export QUAY_TOKEN=your-password`
2) Set your Quay.io credentials so your container engine can login to push:

```shell
export QUAY_USER=your-quay-username
export QUAY_TOKEN=your-quay-password
export RH_REGISTRY_USER=your-redhat-registry-user
export RH_REGISTRY_TOKEN=your-redhat-registry-token
```

3) Build and push the image: `make docker-build-push`

**On Mac:**
Expand Down
45 changes: 45 additions & 0 deletions docs/local-testing-w-notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the steps in this link bring up a db to work with gorm? make migrate makes me think of an in-memory db maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the config is setup to use sqllite by default. The make migrate will call the migrate command which leverages gorm to setup the db.

The config can be manualy changed for postgres if needed and such, but sqllite should be sufficient enough or testing gorm changes i would suspect

$ make migrate 
mkdir -p bin/ && /usr/bin/go build -ldflags "-X cmd.Version=6871f97" -o ./bin/ ./...
./bin/inventory-api migrate --config .inventory-api.yaml
INFO msg=Using config file: .inventory-api.yaml
Log Level is set to: info
Log Level is set to: info
INFO ts=2025-02-12T10:46:02-05:00 caller=log/log.go:30 service.name=inventory-api service.version=0.1.0 trace.id= span.id= group=storage msg=Persistence disabled: false
INFO ts=2025-02-12T10:46:02-05:00 caller=log/log.go:30 service.name=inventory-api service.version=0.1.0 trace.id= span.id= group=storage msg=Using backing storage: sqlite3
INFO ts=2025-02-12T10:46:02-05:00 caller=log/log.go:30 service.name=inventory-api service.version=0.1.0 trace.id= span.id= group=storage msg=Migration successful!

$ sqlite3 inventory.db 
SQLite version 3.46.1 2024-08-13 09:16:08
Enter ".help" for usage hints.
sqlite> .tables
local_inventory_to_resources  resource_history            
relationship_history          resources                   
relationships               

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


By default, Inventory will leverage a SQLite database and create a local db file called `inventory.db`. If you wish to use postgres, you'll need a postgres database running and the config file used in the above doc would need to be updated. An example of configuring Inventory API for postgres can be found [HERE](https://github.com/project-kessel/inventory-api/blob/b19bc4cef8570b8e34f85336067a0b48f9dcf910/inventory-api-compose.yaml#L19)

### 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