From 40b9432fcd5acc60034d57a8ac2e126fb6b372e8 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sun, 20 Apr 2025 18:35:03 -0400 Subject: [PATCH] Set `TGS_INSTANCE_ROOT` env var in event scripts --- .../Components/InstanceFactory.cs | 1 + .../Components/StaticFiles/Configuration.cs | 12 ++++++++++++ tests/DMAPI/BasicOperation/test_event-qwer.sh | 7 +++++++ .../Components/StaticFiles/TestConfiguration.cs | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index b5c93bac69..c7d08ad4b1 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -292,6 +292,7 @@ namespace Tgstation.Server.Host.Components platformIdentifier, fileTransferService, loggerFactory.CreateLogger(), + metadata, generalConfiguration, sessionConfiguration); var eventConsumer = new EventConsumer(configuration); diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs index e1b37b50b3..f5d320ec2d 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs @@ -124,6 +124,11 @@ namespace Tgstation.Server.Host.Components.StaticFiles /// readonly ILogger logger; + /// + /// The the belongs to. + /// + readonly Models.Instance metadata; + /// /// The for . /// @@ -159,6 +164,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles /// The value of . /// The value of . /// The value of . + /// The value of . /// The value of . /// The value of . /// The value of . @@ -171,6 +177,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles IPlatformIdentifier platformIdentifier, IFileTransferTicketProvider fileTransferService, ILogger logger, + Models.Instance metadata, GeneralConfiguration generalConfiguration, SessionConfiguration sessionConfiguration) { @@ -182,6 +189,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles this.platformIdentifier = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier)); this.fileTransferService = fileTransferService ?? throw new ArgumentNullException(nameof(fileTransferService)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); + this.metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); this.generalConfiguration = generalConfiguration ?? throw new ArgumentNullException(nameof(generalConfiguration)); this.sessionConfiguration = sessionConfiguration ?? throw new ArgumentNullException(nameof(sessionConfiguration)); @@ -844,6 +852,10 @@ namespace Tgstation.Server.Host.Components.StaticFiles return $"\"{arg}\""; })), cancellationToken, + new Dictionary + { + { "TGS_INSTANCE_ROOT", metadata.Path! }, + }, readStandardHandles: true, noShellExecute: true)) using (cancellationToken.Register(() => script.Terminate())) diff --git a/tests/DMAPI/BasicOperation/test_event-qwer.sh b/tests/DMAPI/BasicOperation/test_event-qwer.sh index 185bc88fed..26865cb924 100755 --- a/tests/DMAPI/BasicOperation/test_event-qwer.sh +++ b/tests/DMAPI/BasicOperation/test_event-qwer.sh @@ -4,6 +4,13 @@ set -e echo "Running test_event script - $1 - $2" +if [[ -z "${TGS_INSTANCE_ROOT}" ]]; then + echo "TEST ERROR: TGS_INSTANCE_ROOT env var not defined" + exit 1 +fi + +echo "TGS_INSTANCE_ROOT: ${TGS_INSTANCE_ROOT}" + sleep 5 cd $1 diff --git a/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs b/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs index 6df0a9e573..f5e6b9bf5f 100644 --- a/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs +++ b/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs @@ -53,6 +53,10 @@ namespace Tgstation.Server.Host.Components.StaticFiles.Tests Mock.Of(), Mock.Of(), loggerFactory.CreateLogger(), + new Models.Instance + { + Path = "Some path", + }, new GeneralConfiguration(), new SessionConfiguration());