Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure correct appsettings is used #1086

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var containerAppEnvVars = [
secretRef: 'dbconnectionstring'
}
{
name: 'ASPNETCORE_ENVIRONMENT'
name: 'DOTNET_ENVIRONMENT'
value: environment
}
{
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
dockerfile: src/Digdir.Domain.Dialogporten.Janitor/Dockerfile
environment:
- Infrastructure:DialogDbConnectionString=${DB_CONNECTION_STRING}
- ASPNETCORE_ENVIRONMENT=Development
- DOTNET_ENVIRONMENT=Development
command: [ "sync-subject-resource-mappings" ]
depends_on:
dialogporten-postgres:
Expand Down
10 changes: 9 additions & 1 deletion src/Digdir.Domain.Dialogporten.Janitor/Program.cs
arealmaas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;

// Using two-stage initialization to catch startup errors.
Expand Down Expand Up @@ -43,7 +44,12 @@ static void BuildAndRun(string[] args)
// a command is the scope of the application.
builder.Host.UseDefaultServiceProvider(options => options.ValidateScopes = false);

builder.Configuration.AddUserSecrets<Program>();
builder.Configuration
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddUserSecrets<Program>()
.AddEnvironmentVariables();

arealmaas marked this conversation as resolved.
Show resolved Hide resolved
builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
Expand All @@ -61,6 +67,8 @@ static void BuildAndRun(string[] args)

var app = builder.Build();

Log.Information("Current environment: {Environment}", app.Environment.EnvironmentName);
arealmaas marked this conversation as resolved.
Show resolved Hide resolved

app.AddJanitorCommands();

app.Run();
Expand Down
Loading