Files
YABA/API
Carl Tibule a51e61aabc
All checks were successful
ci/woodpecker/tag/api_build Pipeline was successful
ci/woodpecker/tag/api_uploadimage Pipeline was successful
Attempting to fix code first migrations not running against a fresh db
2024-04-10 20:52:31 -05:00
..
2024-04-07 14:51:28 -05:00
2024-04-07 14:51:28 -05:00

YABA: Yet Another Bookmark App

YABA.API - Developer Guide

Running Migrations

When running migrations, .NET seems to be ignoring dependency injection settings. In order to get around this, be sure to add the connection string to the command like. For example, when adding the migration:

    dotnet ef migrations add InitialMigration -p YABA.Data -s YABA.API --context YABABaseContext -- {CONNECTION_STRING_HERE}

When removing last migration:

    dotnet ef migrations remove InitialMigration -p YABA.Data -s YABA.API --context YABABaseContext -- {CONNECTION_STRING_HERE}

When applying migrations:

    dotnet ef database update -p YABA.Data -s YABA.API -c YABABaseContext -- { CONNECTION_STRING_HERE }

As per the documentation on MSDN:

The -- token directs dotnet ef to treat everything that follows as an argument and not try to parse them as options. Any extra arguments not used by dotnet ef are forwarded to the app.

Managing secrets

Best practice dictates that sensitive values should never be committed to source control. To manage secrets locally, this project utilize the secrets manager.

To initialize a secrets manager:

    dotnet user-secrets init --project YABA.API

To set (or override) the value of a secret using a provided key:

    dotnet user-secrets set "Key" "Value" --project YABA.API
    dotnet user-secrets set "Object:Property" "Value" --project YABA.API

To list all secets:

    dotnet user-secrets list --project YABA.API

Docker

To build a dockerized version of the API project:

    docker build { API_PROJECT_ROOT_SOURCE } -f { API_PROJECT_DOCKERFILE_PATH } -t { imagename:tag }

In order to run a container using the image built above, keep the following things in mind:

  • It might be necessary to map container port 80 to another
  • In the absence of a linked user secrets, secrets will have to be passed in to the container as environment variables, prefixed with ASPNETCORE_
    docker run -d -p { HOST_PC_PORT_HERE }:80 --env ASPNETCORE_Object__Property=Value --name { CONTAINER_NAME } {imagename:tag}

Environment variables that are explicitly listed in YABA.API\Dockerfile will have to be properly set for proper operation of the application