Skip to content

Commit

Permalink
chore/local backbone (#94)
Browse files Browse the repository at this point in the history
* chore: add local backbone config

* chore: add scripts

* chore: update docs

* chore: audit fix
  • Loading branch information
jkoenig134 authored Apr 10, 2024
1 parent 3a175d3 commit 06dc16f
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 5 deletions.
102 changes: 102 additions & 0 deletions .dev/appsettings.override.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"Infrastructure": {
"EventBus": {
"Vendor": "RabbitMQ",
"ConnectionInfo": "rabbitmq",
"RabbitMQUsername": "guest",
"RabbitMQPassword": "guest",
"ConnectionRetryCount": 5
},
"SqlDatabase": {
"Provider": "Postgres",
"ConnectionString": "User Id=adminUi;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;"
}
},
"Modules": {
"Challenges": {
"Infrastructure": {
"SqlDatabase": {
"Provider": "Postgres",
"ConnectionString": "User ID=challenges;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;"
}
}
},
"Quotas": {
"Infrastructure": {
"SqlDatabase": {
"Provider": "Postgres",
"ConnectionString": "User ID=quotas;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;"
}
}
},
"Devices": {
"Infrastructure": {
"SqlDatabase": {
"Provider": "Postgres",
"ConnectionString": "User ID=devices;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;"
},
"PushNotifications": {
"Provider": "Dummy"
}
}
},
"Files": {
"Infrastructure": {
"SqlDatabase": {
"Provider": "Postgres",
"ConnectionString": "User ID=files;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;"
},
"BlobStorage": {
"CloudProvider": "Azure",
"ConnectionInfo": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://azurite:10000/devstoreaccount1;"
}
}
},
"Messages": {
"Infrastructure": {
"SqlDatabase": {
"Provider": "Postgres",
"ConnectionString": "User ID=messages;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;"
}
}
},
"Relationships": {
"Infrastructure": {
"SqlDatabase": {
"Provider": "Postgres",
"ConnectionString": "User ID=relationships;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;"
}
}
},
"Synchronization": {
"Infrastructure": {
"SqlDatabase": {
"Provider": "Postgres",
"ConnectionString": "User ID=synchronization;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;"
}
}
},
"Tokens": {
"Infrastructure": {
"SqlDatabase": {
"Provider": "Postgres",
"ConnectionString": "User ID=tokens;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;"
}
}
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Debug"
},
"Enrich": ["FromLogContext", "WithProcessId", "WithThreadId"],
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff}|{Level} - CorrelationId:{CorrelationId} - RequestId:{RequestId} - RequestPath:{RequestPath}{NewLine} {SourceContext}{NewLine} {Message}{NewLine}{Exception}"
}
}
]
}
}
1 change: 1 addition & 0 deletions .dev/compose.backbone.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONSUMERAPI_TAG=v4.2.6
79 changes: 79 additions & 0 deletions .dev/compose.backbone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
services:
consumer-api:
image: ghcr.io/nmshd/backbone-consumer-api:${CONSUMERAPI_TAG}
container_name: consumer-api
hostname: consumer-api
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "8090:8080"
depends_on:
database:
condition: service_started
rabbitmq:
condition: service_started
seed-database:
condition: service_completed_successfully
azure-storage-emulator:
condition: service_started
configs:
- source: Config
target: app/appsettings.override.json

### infrastructure ###

database:
container_name: bkb-postgres
hostname: postgres
image: postgres
environment:
- POSTGRES_PASSWORD=Passw0rd
- POSTGRES_DB=enmeshed
ports:
- 5432:5432
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 5s
timeout: 5s
retries: 5

azure-storage-emulator:
container_name: azure-storage-emulator
hostname: azurite
image: mcr.microsoft.com/azure-storage/azurite
command: azurite -d /data/debug.log -l /data --blobHost "0.0.0.0" --queueHost "0.0.0.0"
ports:
- "10000:10000"

rabbitmq:
container_name: bkb-rabbitmq
hostname: rabbitmq
image: rabbitmq:3.12.10-management-alpine
ports:
- "5672:5672"

### seeds ###

seed-database:
image: postgres
environment:
- PGPASSWORD=Passw0rd
command: /bin/bash -c 'env && apt update -y && apt install -y wget && wget https://raw.githubusercontent.com/nmshd/backbone/capi/${CONSUMERAPI_TAG}/setup-db/setup-postgres.sql -O /setup-postgres.sql && psql -h postgres -U postgres -d enmeshed -f /setup-postgres.sql'
depends_on:
database:
condition: service_healthy

seed-client:
container_name: seed-client
image: ghcr.io/nmshd/backbone-admin-cli:v2.2.1
depends_on:
consumer-api:
condition: service_healthy
command: backbone client create --clientId test --clientSecret test --defaultTier Basic
environment:
Database__Provider: Postgres
Database__ConnectionString: "Server=postgres;Database=enmeshed;User Id=devices;Password=Passw0rd;Port=5432"

configs:
Config:
file: appsettings.override.json
20 changes: 18 additions & 2 deletions README_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,32 @@ To check for outdated dependencies run `npm run outdated`. This will check the r

## How to test

### Setup
### Remote Backbone

To configure the test setup you have to fill the following environment variables:
Set the following environment variables:

- NMSHD_TEST_BASEURL (the backbone baseUrl to test against)
- NMSHD_TEST_CLIENTID (the backbone clientId for the configured baseUrl)
- NMSHD_TEST_CLIENTSECRET (the backbone clientSecret for the configured baseUrl)

> We recommend to persist these variables for example in your `.bashrc` / `.zshrc` or in the Windows environment variables.
### Local Backbone

To start a local backbone, execute the following command:

```shell
npm run start:backbone
```

Set the following environment variables:

- NMSHD_TEST_BASEURL to `http://localhost:8090`
- NMSHD_TEST_CLIENTID to `test`
- NMSHD_TEST_CLIENTSECRET to `test`

> We recommend to persist these variables for example in your `.bashrc` / `.zshrc` or in the Windows environment variables.
### Running the tests

- a specific database: `npm run test:local:[mongodb|lokijs|ferretdb]`
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"lint:prettier": "prettier --check .",
"lint:tsc": "npm run -ws lint:tsc",
"outdated": "ncu -i && ncu -i -ws",
"start:backbone": "docker compose -p runtime-test-backbone --env-file .dev/compose.backbone.env -f .dev/compose.backbone.yml up -d",
"teardown:backbone": "docker compose -p runtime-test-backbone --env-file .dev/compose.backbone.env -f .dev/compose.backbone.yml down -v",
"test:teardown": "docker compose -f .dev/compose.yml down -fsv"
},
"devDependencies": {
Expand Down

0 comments on commit 06dc16f

Please sign in to comment.