From e77e8dae56c90198fe458c34909a41657c36f7e4 Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Sat, 16 Jan 2021 12:40:14 +0000 Subject: [PATCH] Yaml config files --- README.md | 12 ++++++------ build/Version.props | 2 +- src/Tgstation.Server.Host/ServerFactory.cs | 6 +++++- src/Tgstation.Server.Host/Setup/SetupWizard.cs | 14 +++++++++----- .../Tgstation.Server.Host.csproj | 1 + 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 36be4c01b0..cc7de2d763 100644 --- a/README.md +++ b/README.md @@ -78,19 +78,19 @@ Note that this container is meant to be long running. Updates are handled intern Note that automatic configuration reloading is currently not supported in the container. See #1143 -If using manual configuration, before starting your container make sure the aforementioned `appsettings.Production.json` is setup properly. See below +If using manual configuration, before starting your container make sure the aforementioned `appsettings.Production.yml` is setup properly. See below ### Configuring -The first time you run TGS4 you should be prompted with a configuration wizard which will guide you through setting up your appsettings.Production.json +The first time you run TGS4 you should be prompted with a configuration wizard which will guide you through setting up your `appsettings.Production.yml` -This wizard will, generally, run whenever the server is launched without detecting the config json. Follow the instructions below to perform this process manually. +This wizard will, generally, run whenever the server is launched without detecting the config yml. Follow the instructions below to perform this process manually. #### Configuration Methods There are 3 primary supported ways to configure TGS: -- Modify the `appsettings.Production.json` file (Recommended). +- Modify the `appsettings.Production.yml` file (Recommended). - Set environment variables in the form `Section__Subsection=value` or `Section__ArraySubsection__0=value` for arrays. - Set command line arguments in the form `--Section:Subsection=value` or `--Section:ArraySubsection:0=value` for arrays. @@ -98,7 +98,7 @@ The latter two are not recommended as they cannot be dynamically changed at runt #### Manual Configuration -Create an `appsettings.Production.json` file next to `appsettings.json`. This will override the default settings in appsettings.json with your production settings. There are a few keys meant to be changed by hosts. Modifying any config files while the server is running will trigger a safe restart (Keeps DreamDaemon instances running). Note these are all case-sensitive: +Create an `appsettings.Production.yml` file next to `appsettings.json`. This will override the default settings in `appsettings.json` with your production settings. There are a few keys meant to be changed by hosts. Modifying any config files while the server is running will trigger a safe restart (Keeps DreamDaemon instances running). Note these are all case-sensitive: - `General:ConfigVersion`: Suppresses warnings about out of date config versions. You should change this after updating TGS to one with a new config version. The current version can be found on the releases page for your server version (This field did not exist before v4.4.0). @@ -250,7 +250,7 @@ var/global/client_count = 0 ## Remote Access -tgstation-server is an [ASP.Net Core](https://docs.microsoft.com/en-us/aspnet/core/) app based on the Kestrel web server. This section is meant to serve as a general use case overview, but the entire Kestrel configuration can be modified to your liking with the configuration JSON. See [the official documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel) for details. +tgstation-server is an [ASP.Net Core](https://docs.microsoft.com/en-us/aspnet/core/) app based on the Kestrel web server. This section is meant to serve as a general use case overview, but the entire Kestrel configuration can be modified to your liking with the configuration YAML. See [the official documentation](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel) for details. Exposing the builtin Kestrel server to the internet directly over HTTP is highly not reccommended due to the lack of security. The recommended way to expose tgstation-server to the internet is to host it through a reverse proxy with HTTPS support. Here are some step by step examples to achieve this for major web servers. diff --git a/build/Version.props b/build/Version.props index 222901410b..e51d2af857 100644 --- a/build/Version.props +++ b/build/Version.props @@ -4,7 +4,7 @@ 4.7.0 - 2.2.0 + 2.3.0 8.1.1 9.1.1 5.2.10 diff --git a/src/Tgstation.Server.Host/ServerFactory.cs b/src/Tgstation.Server.Host/ServerFactory.cs index 55bbd24e3a..72d601c73d 100644 --- a/src/Tgstation.Server.Host/ServerFactory.cs +++ b/src/Tgstation.Server.Host/ServerFactory.cs @@ -49,7 +49,11 @@ namespace Tgstation.Server.Host var basePath = IOManager.ResolvePath(); IHostBuilder CreateDefaultBuilder() => Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((context, configuration) => configuration.SetBasePath(basePath)); + .ConfigureAppConfiguration((context, builder) => { + builder.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true) + .AddYamlFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.yml", optional: true, reloadOnChange: true); //Allow both appsettings.json and appsettings.yml for backwards compat + + }); var setupWizardHostBuilder = CreateDefaultBuilder() .UseSetupApplication(); diff --git a/src/Tgstation.Server.Host/Setup/SetupWizard.cs b/src/Tgstation.Server.Host/Setup/SetupWizard.cs index 6a7c99e03b..927cb43982 100644 --- a/src/Tgstation.Server.Host/Setup/SetupWizard.cs +++ b/src/Tgstation.Server.Host/Setup/SetupWizard.cs @@ -22,6 +22,7 @@ using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.System; +using YamlDotNet.Serialization; namespace Tgstation.Server.Host.Setup { @@ -841,8 +842,11 @@ namespace Tgstation.Server.Host.Setup { SwarmConfiguration.Section, swarmConfiguration }, }; - var json = JsonConvert.SerializeObject(map, Formatting.Indented); - var configBytes = Encoding.UTF8.GetBytes(json); + var serializer = new SerializerBuilder().Build(); + + var serializedYaml = serializer.Serialize(map); + + var configBytes = Encoding.UTF8.GetBytes(serializedYaml); reloadTcs = new TaskCompletionSource(); @@ -863,9 +867,9 @@ namespace Tgstation.Server.Host.Setup { await console.WriteAsync(e.Message, true, cancellationToken).ConfigureAwait(false); await console.WriteAsync(null, true, cancellationToken).ConfigureAwait(false); - await console.WriteAsync("For your convienence, here's the json we tried to write out:", true, cancellationToken).ConfigureAwait(false); + await console.WriteAsync("For your convienence, here's the yaml we tried to write out:", true, cancellationToken).ConfigureAwait(false); await console.WriteAsync(null, true, cancellationToken).ConfigureAwait(false); - await console.WriteAsync(json, true, cancellationToken).ConfigureAwait(false); + await console.WriteAsync(serializedYaml, true, cancellationToken).ConfigureAwait(false); await console.WriteAsync(null, true, cancellationToken).ConfigureAwait(false); await console.WriteAsync("Press any key to exit...", true, cancellationToken).ConfigureAwait(false); await console.PressAnyKeyAsync(cancellationToken).ConfigureAwait(false); @@ -930,7 +934,7 @@ namespace Tgstation.Server.Host.Setup return; } - var userConfigFileName = String.Format(CultureInfo.InvariantCulture, "appsettings.{0}.json", hostingEnvironment.EnvironmentName); + var userConfigFileName = String.Format(CultureInfo.InvariantCulture, "appsettings.{0}.yml", hostingEnvironment.EnvironmentName); async Task HandleSetupCancel() { diff --git a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj index 3951c10411..b322b33c24 100644 --- a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj +++ b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj @@ -83,6 +83,7 @@ +