Skip to content

Commit 0afcaa3

Browse files
committed
feat: add demo data seeding for development
1 parent 2bab069 commit 0afcaa3

17 files changed

Lines changed: 519 additions & 75 deletions

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ POSTGRES_PASSWORD=postgres
66
# Development defaults used by docker-compose.override.yml
77
OPENIDDICT_ENCRYPTION_KEY=DRjd/GnduI3Efzen9V9BvbNUfc/VKgXltV7Kbk9sMkY=
88
SWAGGER_CLIENT_SECRET=901564A5-E7FE-42CB-B10D-61EF6A8F3654
9+
DEMO_PASSWORD=Demo123!

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ docker compose up --build
176176

177177
This starts PostgreSQL, Auth, API, and Caddy with local HTTPS routing.
178178

179+
### Trust local Caddy certificate (one-time)
180+
181+
macOS:
182+
183+
```bash
184+
./scripts/setup-local-trust.sh
185+
```
186+
187+
Windows (PowerShell as Administrator):
188+
189+
```powershell
190+
./scripts/setup-local-trust.ps1
191+
```
192+
179193
---
180194

181195
## Testing

TaskManagementServer.sln

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-co
2121
EndProject
2222
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{86A03EC8-9DCB-4B52-BE83-DA02C59E8593}"
2323
ProjectSection(SolutionItems) = preProject
24-
scripts\create-database.sql = scripts\create-database.sql
24+
scripts\setup-local-trust.ps1 = scripts\setup-local-trust.ps1
25+
scripts\setup-local-trust.sh = scripts\setup-local-trust.sh
2526
EndProjectSection
2627
EndProject
2728
Global

docker-compose.override.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ services:
1111
- OpenIddict__Issuer=https://auth.localhost
1212
- OpenIddict__Audience=task_management_api_dev
1313
- OpenIddict__EncryptionKey=${OPENIDDICT_ENCRYPTION_KEY:-DRjd/GnduI3Efzen9V9BvbNUfc/VKgXltV7Kbk9sMkY=}
14+
- DemoData__Enabled=true
15+
- DemoData__DefaultPassword=${DEMO_PASSWORD:-Demo123!}
1416
- ClientSettings__Clients__0__ClientId=swagger-client
1517
- ClientSettings__Clients__0__ClientSecret=${SWAGGER_CLIENT_SECRET:-901564A5-E7FE-42CB-B10D-61EF6A8F3654}
1618
- ClientSettings__Clients__0__DisplayName=Swagger Client application
@@ -21,18 +23,6 @@ services:
2123
- ClientSettings__Clients__0__AllowedCorsOrigins__2=https://localhost:8081
2224
- ClientSettings__Clients__0__AllowedScopes__0=api1
2325
- ClientSettings__Clients__0__RequirePkce=true
24-
- SeedUsers__0__Email=demo-admin@example.com
25-
- SeedUsers__0__DisplayName=Demo Admin
26-
- SeedUsers__0__Password=Demo123!
27-
- SeedUsers__0__Role=Administrator
28-
- SeedUsers__1__Email=demo-manager@example.com
29-
- SeedUsers__1__DisplayName=Demo Manager
30-
- SeedUsers__1__Password=Demo123!
31-
- SeedUsers__1__Role=ProjectManager
32-
- SeedUsers__2__Email=demo-user@example.com
33-
- SeedUsers__2__DisplayName=Demo User
34-
- SeedUsers__2__Password=Demo123!
35-
- SeedUsers__2__Role=User
3626

3727
api-service:
3828
extra_hosts:
@@ -44,6 +34,7 @@ services:
4434
- OpenIddict__Issuer=https://auth.localhost
4535
- OpenIddict__Audience=task_management_api_dev
4636
- OpenIddict__EncryptionKey=${OPENIDDICT_ENCRYPTION_KEY:-DRjd/GnduI3Efzen9V9BvbNUfc/VKgXltV7Kbk9sMkY=}
37+
- DemoData__Enabled=true
4738
- AuthApi__BaseUrl=https://auth.localhost/
4839
- ClientSettings__AuthorizationUrl=https://auth.localhost/connect/authorize
4940
- ClientSettings__TokenUrl=https://auth.localhost/connect/token

scripts/create-database.sql

Lines changed: 0 additions & 16 deletions
This file was deleted.

scripts/setup-local-trust.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
param(
2+
[string]$ContainerName = "caddy-prox",
3+
[string]$CertOutputPath = "$env:TEMP\caddy-local-root.crt"
4+
)
5+
6+
$ErrorActionPreference = "Stop"
7+
8+
function Ensure-Command {
9+
param([string]$Name)
10+
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
11+
throw "Required command '$Name' was not found in PATH."
12+
}
13+
}
14+
15+
Ensure-Command docker
16+
Ensure-Command certutil
17+
18+
Write-Host "Ensuring Caddy container is running..."
19+
docker compose up -d caddy | Out-Null
20+
21+
$running = docker ps --format '{{.Names}}' | Select-String -SimpleMatch $ContainerName
22+
if (-not $running) {
23+
Write-Host "Container '$ContainerName' is not running. Start stack first:"
24+
Write-Host " docker compose up -d --build"
25+
exit 1
26+
}
27+
28+
Write-Host "Exporting Caddy local root certificate..."
29+
docker cp "$ContainerName`:/data/caddy/pki/authorities/local/root.crt" "$CertOutputPath"
30+
31+
Write-Host "Installing certificate into Windows Trusted Root Certification Authorities..."
32+
certutil -addstore -f "Root" "$CertOutputPath" | Out-Null
33+
34+
Write-Host "Certificate installed successfully."
35+
Write-Host "Restart your browser and open:"
36+
Write-Host " https://api.localhost/health"
37+
Write-Host " https://auth.localhost"

scripts/setup-local-trust.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [[ "${OSTYPE:-}" != darwin* ]]; then
5+
echo "This helper currently supports macOS only."
6+
echo "For other OSes, trust Caddy local CA from: /data/caddy/pki/authorities/local/root.crt"
7+
exit 1
8+
fi
9+
10+
if ! command -v docker >/dev/null 2>&1; then
11+
echo "Docker is not installed or not available in PATH."
12+
exit 1
13+
fi
14+
15+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
server_dir="$(cd "${script_dir}/.." && pwd)"
17+
cert_path="/tmp/caddy-local-root.crt"
18+
container_name="caddy-prox"
19+
20+
echo "Ensuring Caddy container is running..."
21+
(
22+
cd "${server_dir}"
23+
docker compose up -d caddy >/dev/null
24+
)
25+
26+
if ! docker ps --format '{{.Names}}' | grep -qx "${container_name}"; then
27+
echo "Could not find running container '${container_name}'."
28+
echo "Start the stack first with: docker compose up -d --build"
29+
exit 1
30+
fi
31+
32+
echo "Exporting Caddy local root certificate..."
33+
docker cp "${container_name}:/data/caddy/pki/authorities/local/root.crt" "${cert_path}"
34+
35+
echo "Installing certificate into macOS System keychain (sudo required)..."
36+
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "${cert_path}"
37+
38+
echo "Certificate installed successfully."
39+
echo "Restart your browser and open:"
40+
echo " https://api.localhost/health"
41+
echo " https://auth.localhost"

src/TaskManagement.Api/Infrastructure/Persistence/Configuration/DatabaseConfiguration.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.EntityFrameworkCore;
22
using Microsoft.Extensions.Configuration;
3+
using TaskManagement.Api.Infrastructure.Persistence.Seeding;
34

45
namespace TaskManagement.Api.Infrastructure.Persistence.Configuration
56
{
@@ -61,6 +62,11 @@ public static async Task ApplyMigrationsAsync(this WebApplication app)
6162
{
6263
logger.LogError(ex, "Migration error in API service");
6364
}
65+
66+
if (app.Environment.IsDevelopment())
67+
{
68+
await services.SeedDemoDataAsync(logger);
69+
}
6470
}
6571
}
6672
}

0 commit comments

Comments
 (0)