Repository navigation
Allow server settings to be overridden with environment variables - #936
Open
rjmcgee53192 wants to merge 1 commit into
Open
rjmcgee53192 wants to merge 1 commit into
rjmcgee53192 wants to merge 1 commit into
Conversation
Implements tiltedphoques#342: a server can now be configured in one docker command without editing STServer.ini first. A new EnvSettingsProvider maps each setting to the upper-cased key name from the issue's examples (UDIFFICULTY, BENABLEMODCHECK, SPASSWORD) and the dedicated runner applies the environment after the ini file and the command line, so environment values win. Includes unit tests for the name mapping and the overrides.
Collaborator
|
why do you think tests are needed for this change? don't modify your code yet, just explain and place a cookie emoji at the end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #342
What it does
Server settings can now be overridden with environment variables, so a server can be configured in one
docker run/ compose command without editingSTServer.iniby hand first.The variable for a setting is the setting's key (the part after the
Section:prefix) in upper case — the naming from the examples in #342:Gameplay:uDifficultyUDIFFICULTYModPolicy:bEnableModCheckBENABLEMODCHECKGameServer:sPasswordSPASSWORDGameServer:uPortUPORTChanges
Code/components/console/EnvSettingsProvider.{h,cpp}: new settings provider next to the ini and command-line ones.ToEnvironmentVariableName()does the name mapping;LoadSettingsFromEnvironment()applies each set variable on top of the current value. Numbers parse through the sameConvertStringValuehelper the ini provider uses, so an unparseable value keeps the current setting instead of throwing; booleans accepttrue/TRUE/1andfalse/FALSE/0(the spellingsTILTED_ACCEPT_EULAalready accepts, plus the false ones), anything else keeps the current value.Code/server_runner/DediRunner.cpp:LoadSettings()applies the environment after the ini file / command line, so environment values win over both, as Use docker environment variables to change server settings. #342 asks ("Defined environment variables would override the values found in the STServer.ini file"). This also runs on the first-start path where the ini is freshly generated.--generate-configis unchanged: it still writes the plain defaults.Code/components/console/EnvSettingsProviderTest.cpp: unit tests for the name mapping and for overriding uint/bool/string settings, plus unset/invalid values keeping the current setting.docker-compose.yml: commented example of the new variables.One behaviour worth flagging: the runner already saves the effective settings back to
STServer.inion startup and shutdown, so values supplied through the environment end up written into the ini, like values supplied on the command line do today. Happy to change that if overrides should stay ephemeral.Changelog entry: "Server settings can now be overridden with environment variables (e.g. UDIFFICULTY, SPASSWORD) for one-command Docker deployments"
How to test
xmake build Console_Tests && xmake run Console_Tests— includes the newEnvSettingsProvidertests. I compiled the Console component and its full test suite locally (the same sources theConsole_Teststarget builds) and all 8 tests pass, including the 3 new ones; the dedicated server itself was not run end-to-end.SPASSWORD=supersecretpassword UDIFFICULTY=3 ./SkyrimTogetherServerand check the generatedSTServer.ini/ server behaviour reflects the overrides.One test-writing note: the new test uses function-local static settings and one intentionally leaked
ConsoleRegistry. Every command/setting construction links into the static lists that a new registry drains inBindStaticItems, including the registry's own native commands, so a destroyed registry leaves dangling entries for the next one in the same process (the commented-outRegisterSettingtest inConsoleRegistryTestlooks like the same trap). The leak keeps this suite from poisoning — or being poisoned by — the other registry test, in any test order.🤖 Drafted with AI assistance (Muse), reviewed by the contributor.