Skip to content

Commit

Permalink
Adjusting appsettings load (#13)
Browse files Browse the repository at this point in the history
* adjusting appsettings load

* typo in log

* updating app settings load
  • Loading branch information
bigtallcampbell committed Aug 2, 2024
1 parent 34c1986 commit 3271926
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
using Microsoft.Extensions.Configuration;
namespace Microsoft.Azure.SpaceFx.PlatformServices.Deployment;

public class Program {
public static void Main(string[] args) {
var builder = WebApplication.CreateBuilder(args);

string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set");
// Load the configuration being supplicated by the cluster first
builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false);
builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false);
string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
if (!string.IsNullOrWhiteSpace(dotnet_env))
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false);



builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))
.ConfigureServices((services) => {
Expand Down
7 changes: 5 additions & 2 deletions test/debugClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ public class Program {
public static void Main(string[] args) {
var builder = WebApplication.CreateBuilder(args);

string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set");
// Load the configuration being supplicated by the cluster first
builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false);
builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false);
string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
if (!string.IsNullOrWhiteSpace(dotnet_env))
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false);

builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))
.ConfigureServices((services) => {
Expand Down
7 changes: 5 additions & 2 deletions test/integrationTests/TestSharedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ public TestSharedContext() {
K8S_CLIENT = new k8s.Kubernetes(config);

var builder = WebApplication.CreateBuilder();
string _secretDir = Environment.GetEnvironmentVariable("SPACEFX_SECRET_DIR") ?? throw new Exception("SPACEFX_SECRET_DIR environment variable not set");
// Load the configuration being supplicated by the cluster first
builder.Configuration.AddJsonFile(Path.Combine("{env:SPACEFX_CONFIG_DIR}", "config", "appsettings.json"), optional: true, reloadOnChange: false);
builder.Configuration.AddJsonFile(Path.Combine($"{_secretDir}", "config", "appsettings.json"), optional: false, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"), optional: true, reloadOnChange: false);

// Load any local appsettings incase they're overriding the cluster values
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.{env:DOTNET_ENVIRONMENT}.json"), optional: true, reloadOnChange: false);
string? dotnet_env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
if (!string.IsNullOrWhiteSpace(dotnet_env))
builder.Configuration.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{dotnet_env}.json"), optional: true, reloadOnChange: false);

builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(50051, o => o.Protocols = HttpProtocols.Http2))
.ConfigureServices((services) => {
Expand Down

0 comments on commit 3271926

Please sign in to comment.