|
| 1 | +# SharpCoreDB Server × .NET Aspire Integration |
| 2 | + |
| 3 | +> **Status:** SharpCoreDB-side prerequisites implemented · **Date:** 2026-09-05 |
| 4 | +> |
| 5 | +> This repository delivers the two SharpCoreDB prerequisites defined by the SCDMS design doc |
| 6 | +> [`docs/aspire.md`](https://github.com/MPCoreDeveloper/SCDMS/blob/main/docs/aspire.md) |
| 7 | +> (SCDMS issue #10). Once the `SCDMS.Aspire.Hosting` package is built in the SCDMS repository, |
| 8 | +> SharpCoreDB server + SCDMS can run as one Aspire application with all SCDMS ⇄ SharpCoreDB |
| 9 | +> traffic over **gRPC**. |
| 10 | +
|
| 11 | +## Goal (from the SCDMS design doc) |
| 12 | + |
| 13 | +Run SharpCoreDB server + SCDMS as a single Aspire app, like pgAdmin next to PostgreSQL: |
| 14 | + |
| 15 | +```csharp |
| 16 | +var builder = DistributedApplication.CreateBuilder(args); |
| 17 | + |
| 18 | +var sharpCoreDb = builder.AddSharpCoreDB("db") |
| 19 | + .WithServerContainer(); // SharpCoreDB server container |
| 20 | +
|
| 21 | +builder.AddSCDMS("admin") |
| 22 | + .WithGrpcReference(sharpCoreDb) // SCDMS container linked via gRPC |
| 23 | + .WithHttpEndpoint(port: 8080, name: "http"); |
| 24 | + |
| 25 | +builder.Build().Run(); |
| 26 | +``` |
| 27 | + |
| 28 | +## What this repository now provides |
| 29 | + |
| 30 | +### 1. Server container image → `ghcr.io/mpcoredeveloper/sharpcoredb-server` |
| 31 | + |
| 32 | +- `.github/workflows/docker-publish.yml` builds and pushes the server image on every `v*` tag |
| 33 | + and via `workflow_dispatch`. |
| 34 | +- Multi-architecture: `linux/amd64` + `linux/arm64` (Docker Buildx + QEMU). |
| 35 | +- Tags: `<version>` (tag without the leading `v`) and `latest`. |
| 36 | +- Build context is the repository root; the Dockerfile lives at |
| 37 | + `src/SharpCoreDB.Server/Dockerfile`. |
| 38 | + |
| 39 | +### 2. `SharpCoreDB.Aspire.Hosting` NuGet package |
| 40 | + |
| 41 | +The package (project `src/SharpCoreDB.Aspire.Hosting/`) registers the server container in an |
| 42 | +Aspire application: |
| 43 | + |
| 44 | +```csharp |
| 45 | +using SharpCoreDB.Aspire.Hosting; |
| 46 | + |
| 47 | +var builder = DistributedApplication.CreateBuilder(args); |
| 48 | + |
| 49 | +var db = builder.AddSharpCoreDB("db") // ghcr.io/mpcoredeveloper/sharpcoredb-server:latest |
| 50 | + .WithServerContainer() |
| 51 | + .WithImageTag("2.0.0.2") // optional pinned tag |
| 52 | + .WithJwtSecret("a-secret-of-at-least-32-characters"); |
| 53 | + |
| 54 | +builder.Build().Run(); |
| 55 | +``` |
| 56 | + |
| 57 | +The resource (`SharpCoreDbServerResource`) implements `IResourceWithConnectionString` and always |
| 58 | +exposes **two** HTTPS endpoints: |
| 59 | + |
| 60 | +| Endpoint | Container port | Purpose | |
| 61 | +|---|---|---| |
| 62 | +| `grpc` | 5001 | Primary gRPC protocol (HTTP/2), matching `Server.GrpcPort` | |
| 63 | +| `https` | 8443 | HTTPS REST API + `/health`, matching `Server.HttpsApiPort` | |
| 64 | + |
| 65 | +The connection string of the resource points at the gRPC endpoint: |
| 66 | +`Host=<host>;Port=<port>;SSL=True`. |
| 67 | + |
| 68 | +## TLS in development (important) |
| 69 | + |
| 70 | +SharpCoreDB server **enforces TLS 1.2+** and refuses to start on plain HTTP |
| 71 | +(`Server.Security.TlsEnabled` must stay `true` and a certificate path is required). Both |
| 72 | +endpoints are therefore modeled with `WithHttpsEndpoint` in the hosting package. |
| 73 | + |
| 74 | +- **Production / behind a reverse proxy:** terminate TLS at a publicly trusted proxy (see the |
| 75 | + SCDMS `samples/docker/` pattern) and mount the real certificate into `/app/certs`. |
| 76 | +- **Local Aspire development:** the container still needs a certificate. Use the Aspire |
| 77 | + development certificate (trust it in the consuming client) or mount a development PFX and |
| 78 | + point `Server__Security__TlsCertificatePath` at it. gRPC clients in development may need |
| 79 | + certificate validation disabled for the local `grpc` endpoint. |
| 80 | + |
| 81 | +## Environment configuration |
| 82 | + |
| 83 | +| Setting | Container env var | Notes | |
| 84 | +|---|---|---| |
| 85 | +| JWT secret | `Server__Security__JwtSecretKey` | Min. 32 chars; use `WithJwtSecret(...)` | |
| 86 | +| TLS cert | `Server__Security__TlsCertificatePath` | Default `./certs/server.pfx`; mount into `/app/certs` | |
| 87 | +| HTTPS API | `Server__EnableHttpsApi` / `Server__HttpsApiPort` | Defaults `true` / `8443` | |
| 88 | +| gRPC | `Server__EnableGrpc` / `Server__GrpcPort` | Defaults `true` / `5001` | |
| 89 | + |
| 90 | +## Consuming the resource from another hosting package |
| 91 | + |
| 92 | +`WithGrpcReference` (to be added by `SCDMS.Aspire.Hosting`) can resolve the gRPC endpoint and |
| 93 | +forward `SCDMS__DefaultServer*` settings: |
| 94 | + |
| 95 | +```csharp |
| 96 | +var grpcEndpoint = sharpCoreDb.GetEndpoint("grpc"); |
| 97 | +scdms.WithEnvironment("SCDMS__DefaultServerHost", grpcEndpoint) |
| 98 | + .WithEnvironment("SCDMS__DefaultServerPort", grpcEndpoint.Property(EndpointProperty.Port)) |
| 99 | + .WithEnvironment("SCDMS__DefaultServerUseSsl", "true"); |
| 100 | +``` |
| 101 | + |
| 102 | +## Related |
| 103 | + |
| 104 | +- Server quick start: [`QUICKSTART.md`](QUICKSTART.md) |
| 105 | +- Server configuration reference: [`CONFIGURATION_SCHEMA.md`](CONFIGURATION_SCHEMA.md) |
| 106 | +- Server Docker Compose: `src/SharpCoreDB.Server/docker-compose.yml` |
| 107 | +- SCDMS Aspire design doc (the plan this implements): |
| 108 | + https://github.com/MPCoreDeveloper/SCDMS/blob/main/docs/aspire.md |
0 commit comments