Disclaimer: During the creation of this project code, LLM was used.
This project will be a starting point for a web application with authorization and authentification set up. Backend will be in dotnet, backed by a Postgres db.
We want to need minimal setup on the developer machine when working using this project. Therefore, everything will be ready to build and run using docker images.
Build and run dev:
docker-compose -f docker/docker-compose.dev.yml up -d --build
- Waits for postgresdb container to be started
- Runs
dotnet watch runto allow hot reload - To force rebuild, first kill the
loginnet-devcontainer
If you need to run some tools (for example migrations)
docker-compose -f docker/docker-compose.dev.yml run --build -it loginnet /bin/bash
- Runs the loginnet-dev container (without
dotnet watch run) and puts you into shell
Build and run prod:
docker-compose -f docker/docker-compose.prod.yml up -d --build
Run all tests:
docker-compose -f docker/docker-compose.test.yml run --build --rm loginnet-tests
Run tests from inside a container shell (for interactive testing):
docker-compose -f docker/docker-compose.test.yml run --build --rm -it loginnet-tests sh
# Inside container:
cd /app/server.tests
dotnet test --verbosity normal
The test suite includes comprehensive tests for role permission inheritance logic:
- CanRegisterUsers Tests: Validates that users can register other users in roles based on hierarchical permission inheritance
- CanCreateRoles Tests: Validates that users can create sub-roles based on hierarchical permission inheritance
Tests use in-memory databases and do not require PostgreSQL.
Backend template generation using docker image:
docker run --rm \
-v "$PWD:/workdir" \
-w "/workdir" \
mcr.microsoft.com/dotnet/sdk:10.0 \
dotnet new web -o server
Runs dotnet new web -o server using the dotnet-sdk docker container inside /workdir directory. Current $PWD is mapped to the /workdir.
Set up secure PosgresDb password in docker/.env POSTGRES_PASSWORD
Set up JWT key in docker/.env. Must be 256 bits, base 64 encoded. Use openssl rand -base64 32 to generate.
There is no need for launchSettings.json to set port and everything. When run through docker, it uses values set by env variables.
The app does not take care of tls and does not expose https port. This should be a job of a reverse proxy.
We ignore ./src/server/bin and ./src/server/obj in docker build (do not copy from build context to the image). Some tools (vscode+omnisharp) create these automatically even when we do not build localy. However, during the build of the docker, we want the dotnet to create its own. Also, during dev, when we map ./src, we want to avoid mapping these, so not to mix these.