Sample of Web API and tests with Database in Docker, along with "build as code" using Nuke Build.
Key features:
- ASP.NET Core 8.0
- Entity Framework Core 7.0 & PostgreSQL
- Build solution using Nuke build
- Dockerfile automatic generation support using Scriban
- API client generation using NSwag
- Integration tests with Docker using TestContainers and Respawn
- Docker Compose to run all prerequisites (PostgreSQL, Grafana, Jaeger, Prometheus)
- Logging using Serilog with Loki
- Metrics using OpenTelemetry and Prometheus
- Tracing using OpenTelemetry and Jaeger
In order to run the API, you need to have a PostgreSQL database running. You can use the provided Docker Compose file to run it.
List of services:
- PostgreSQL:
localhost:5432
- Grafana:
https://localhost:3000
- Jaeger:
https://localhost:16686
- Prometheus:
https://localhost:9090
- Loki:
https://localhost:3100
Starts the HTTP-server
Execute all tests
dotnet test
Execute only integration tests
dotnet test --filter Category=IntegrationTests
#Install EF utils
dotnet tool install --global dotnet-ef
#Create schema migration
dotnet ef migrations add <Name of your migration> --startup-project src/Api -p src/Store -c PopulationDbContext
Install the global tool
dotnet tool install Nuke.GlobalTool --global
nuke
Execute from the root of the repository
pwsh build.ps1 -DockerRepositoriesUrl https://some.docker.registry -Branch some-dev-branch -BuildCounter 1 -DockerRepositoryName some-docker-repo-name -NuGetUrl https://some.nuget.registry -NuGetFeedName some-nuget-feed-name -NuGetApiKey some-nuget-api-key
Execute the following command to see the interactive execution plan
nuke --plan
API client is generated using NSwag tool.
It generates automatically when ClientGenerator project is built.
See more details in NSwag documentation and nswag.json file.
To see current app metrics, go to https://localhost:5005/metrics
Grafana runs automatically using Docker Compose and is available at https://localhost:3000. It has three predefined data sources:
- Prometheus
- Loki
- Jaeger