From f4ab1a74e5afb2788ef4dee45eddac8345765211 Mon Sep 17 00:00:00 2001 From: ZephyrTFA Date: Mon, 19 Aug 2024 13:23:44 -0400 Subject: [PATCH] allow on docker --- build/Dockerfile | 1 + .../Components/InstanceManager.cs | 10 +++++++++- .../Configuration/InternalConfiguration.cs | 9 ++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index b301591833..c281147ddd 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -69,6 +69,7 @@ EXPOSE 5000 ENV General__ValidInstancePaths__0 /tgs_instances ENV FileLogging__Directory /tgs_logs +ENV Internal__UsingDocker true WORKDIR /app diff --git a/src/Tgstation.Server.Host/Components/InstanceManager.cs b/src/Tgstation.Server.Host/Components/InstanceManager.cs index 73fdf2b857..756d4b726c 100644 --- a/src/Tgstation.Server.Host/Components/InstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/InstanceManager.cs @@ -130,6 +130,11 @@ namespace Tgstation.Server.Host.Components /// readonly SwarmConfiguration swarmConfiguration; + /// + /// The for the . + /// + readonly InternalConfiguration internalConfiguration; + /// /// The for . /// @@ -177,6 +182,7 @@ namespace Tgstation.Server.Host.Components /// The value of . /// The containing the value of . /// The containing the value of . + /// The containing the value of . /// The value of . public InstanceManager( IInstanceFactory instanceFactory, @@ -193,6 +199,7 @@ namespace Tgstation.Server.Host.Components IPlatformIdentifier platformIdentifier, IOptions generalConfigurationOptions, IOptions swarmConfigurationOptions, + IOptions internalConfigurationOptions, ILogger logger) { this.instanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory)); @@ -209,6 +216,7 @@ namespace Tgstation.Server.Host.Components this.platformIdentifier = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier)); generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); swarmConfiguration = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions)); + internalConfiguration = internalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(internalConfigurationOptions)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); originalConsoleTitle = console.Title; @@ -676,7 +684,7 @@ namespace Tgstation.Server.Host.Components if (!systemIdentity.CanCreateSymlinks) throw new InvalidOperationException($"The user running {Constants.CanonicalPackageName} cannot create symlinks! Please try running as an administrative user!"); - if (!platformIdentifier.IsWindows && systemIdentity.IsSuperUser) + if (!platformIdentifier.IsWindows && systemIdentity.IsSuperUser && !internalConfiguration.UsingDocker) { logger.LogWarning("TGS is being run as the root account. This is not recommended and may prevent launch in a future version."); } diff --git a/src/Tgstation.Server.Host/Configuration/InternalConfiguration.cs b/src/Tgstation.Server.Host/Configuration/InternalConfiguration.cs index 58f2ad4720..b060a3bd93 100644 --- a/src/Tgstation.Server.Host/Configuration/InternalConfiguration.cs +++ b/src/Tgstation.Server.Host/Configuration/InternalConfiguration.cs @@ -1,4 +1,6 @@ -namespace Tgstation.Server.Host.Configuration +using System; + +namespace Tgstation.Server.Host.Configuration { /// /// Unstable configuration options used internally by TGS. @@ -25,6 +27,11 @@ /// public bool UsingSystemD { get; set; } + /// + /// If the server is running inside of a Docker container. + /// + public bool UsingDocker => Environment.GetEnvironmentVariable("Internal__UsingDocker")?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false; + /// /// The base path for the app settings configuration files. ///