From 8ed2ba01c03c22433daa899055f373b6be5585ea Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Mon, 30 May 2022 18:20:58 +0200 Subject: [PATCH 01/16] Add parameters for basic handling of mods --- Dockerfile | 2 ++ launch.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/Dockerfile b/Dockerfile index d122524..8d62b97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,6 +62,8 @@ ENV GAME_PROPS_FAST_VALIDATION=true ENV GAME_PROPS_SERVER_MAX_VIEW_DISTANCE=2500 ENV GAME_PROPS_SERVER_MIN_GRASS_DISTANCE=50 ENV GAME_PROPS_NETWORK_VIEW_DISTANCE=1000 +ENV GAME_MODS_IDS_LIST="" +ENV GAME_MODS_JSON_FILE="" ENV SKIP_INSTALL=false diff --git a/launch.py b/launch.py index 38e83ed..c342e54 100644 --- a/launch.py +++ b/launch.py @@ -109,6 +109,17 @@ def bool_str(text): config["game"]["gameProperties"]["networkViewDistance"] = int( os.environ["GAME_PROPS_NETWORK_VIEW_DISTANCE"] ) + if env_defined("GAME_MODS_IDS_LIST"): # This will overwrite mods from GAME_MODS_JSON_FILE + config["game"]["mods"] = [] + mod_ids = os.environ["GAME_MODS_IDS_LIST"].split(",") + for mod in mod_ids: + config["game"]["mods"].append({ + "modId": mod, + "name": "", + }) + if env_defined("GAME_MODS_JSON_FILE"): # This will overwrite mods from GAME_MODS_IDS_LIST + with open(os.environ["GAME_MODS_JSON_FILE"]) as f: + config["game"]["mods"] = json.load(f) f = open(CONFIG_GENERATED, "w") json.dump(config, f, indent=4) From c651c83cd4558bbb34bdb674d88e9b23563a049a Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Mon, 30 May 2022 18:22:57 +0200 Subject: [PATCH 02/16] Fix misleading comment --- launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch.py b/launch.py index c342e54..4756896 100644 --- a/launch.py +++ b/launch.py @@ -109,7 +109,7 @@ def bool_str(text): config["game"]["gameProperties"]["networkViewDistance"] = int( os.environ["GAME_PROPS_NETWORK_VIEW_DISTANCE"] ) - if env_defined("GAME_MODS_IDS_LIST"): # This will overwrite mods from GAME_MODS_JSON_FILE + if env_defined("GAME_MODS_IDS_LIST"): config["game"]["mods"] = [] mod_ids = os.environ["GAME_MODS_IDS_LIST"].split(",") for mod in mod_ids: From a32928c0af661c590c0f5ab1ec47671d552946ab Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Mon, 30 May 2022 18:42:38 +0200 Subject: [PATCH 03/16] Add basic checks, more accurate name for mods json file param --- Dockerfile | 2 +- launch.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8d62b97..f06b766 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,7 +63,7 @@ ENV GAME_PROPS_SERVER_MAX_VIEW_DISTANCE=2500 ENV GAME_PROPS_SERVER_MIN_GRASS_DISTANCE=50 ENV GAME_PROPS_NETWORK_VIEW_DISTANCE=1000 ENV GAME_MODS_IDS_LIST="" -ENV GAME_MODS_JSON_FILE="" +ENV GAME_MODS_JSON_FILE_PATH="" ENV SKIP_INSTALL=false diff --git a/launch.py b/launch.py index 4756896..355eb94 100644 --- a/launch.py +++ b/launch.py @@ -1,7 +1,9 @@ import json import os import random +import re import subprocess +import sys CONFIG_GENERATED = "/reforger/Configs/docker_generated.json" @@ -109,16 +111,23 @@ def bool_str(text): config["game"]["gameProperties"]["networkViewDistance"] = int( os.environ["GAME_PROPS_NETWORK_VIEW_DISTANCE"] ) + if env_defined("GAME_MODS_IDS_LIST") and env_defined("GAME_MODS_JSON"): + print("Mutually exclusive parameters specified - GAME_MODS_IDS_LIST and GAME_MODS_JSON, please remove one") + sys.exit(1) if env_defined("GAME_MODS_IDS_LIST"): config["game"]["mods"] = [] + reg = re.compile("^[A-Z0-9,]+$") + if not reg.match(str(os.environ["GAME_MODS_IDS_LIST"])): + print("Illegal characters in GAME_MODS_IDS_LIST env") + sys.exit(1) mod_ids = os.environ["GAME_MODS_IDS_LIST"].split(",") for mod in mod_ids: config["game"]["mods"].append({ "modId": mod, "name": "", }) - if env_defined("GAME_MODS_JSON_FILE"): # This will overwrite mods from GAME_MODS_IDS_LIST - with open(os.environ["GAME_MODS_JSON_FILE"]) as f: + if env_defined("GAME_MODS_JSON_FILE_PATH"): + with open(os.environ["GAME_MODS_JSON_FILE_PATH"]) as f: config["game"]["mods"] = json.load(f) f = open(CONFIG_GENERATED, "w") From 5ae310c6f0e31eac865f0c38c21153e4da2a0985 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Mon, 30 May 2022 19:32:34 +0200 Subject: [PATCH 04/16] Adjust Dockerfile lines reference in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8729893..e957d1d 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Simply check-out / copy [the provided docker-compose.yml](docker-compose.yml) an ## Parameters -Check [the Dockerfile](Dockerfile#L32-L64), more docs will come later. +Check [the Dockerfile](Dockerfile#L32-L66), more docs will come later. ### Configs From 1999008b3391d4ec0f12503d4c10cecd790270a4 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Mon, 30 May 2022 19:36:17 +0200 Subject: [PATCH 05/16] Adjust formatting for black linter --- launch.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/launch.py b/launch.py index 355eb94..aec7b7d 100644 --- a/launch.py +++ b/launch.py @@ -112,7 +112,9 @@ def bool_str(text): os.environ["GAME_PROPS_NETWORK_VIEW_DISTANCE"] ) if env_defined("GAME_MODS_IDS_LIST") and env_defined("GAME_MODS_JSON"): - print("Mutually exclusive parameters specified - GAME_MODS_IDS_LIST and GAME_MODS_JSON, please remove one") + print( + "Mutually exclusive parameters specified - GAME_MODS_IDS_LIST and GAME_MODS_JSON, please remove one" + ) sys.exit(1) if env_defined("GAME_MODS_IDS_LIST"): config["game"]["mods"] = [] @@ -122,10 +124,12 @@ def bool_str(text): sys.exit(1) mod_ids = os.environ["GAME_MODS_IDS_LIST"].split(",") for mod in mod_ids: - config["game"]["mods"].append({ - "modId": mod, - "name": "", - }) + config["game"]["mods"].append( + { + "modId": mod, + "name": "", + } + ) if env_defined("GAME_MODS_JSON_FILE_PATH"): with open(os.environ["GAME_MODS_JSON_FILE_PATH"]) as f: config["game"]["mods"] = json.load(f) From 839d543b68ad8e2e4c0f5ae903ae998a48bb5130 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Mon, 30 May 2022 21:33:35 +0200 Subject: [PATCH 06/16] Allow both JSON and IDs in the env --- launch.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/launch.py b/launch.py index aec7b7d..3e431c0 100644 --- a/launch.py +++ b/launch.py @@ -111,13 +111,7 @@ def bool_str(text): config["game"]["gameProperties"]["networkViewDistance"] = int( os.environ["GAME_PROPS_NETWORK_VIEW_DISTANCE"] ) - if env_defined("GAME_MODS_IDS_LIST") and env_defined("GAME_MODS_JSON"): - print( - "Mutually exclusive parameters specified - GAME_MODS_IDS_LIST and GAME_MODS_JSON, please remove one" - ) - sys.exit(1) if env_defined("GAME_MODS_IDS_LIST"): - config["game"]["mods"] = [] reg = re.compile("^[A-Z0-9,]+$") if not reg.match(str(os.environ["GAME_MODS_IDS_LIST"])): print("Illegal characters in GAME_MODS_IDS_LIST env") @@ -132,7 +126,9 @@ def bool_str(text): ) if env_defined("GAME_MODS_JSON_FILE_PATH"): with open(os.environ["GAME_MODS_JSON_FILE_PATH"]) as f: - config["game"]["mods"] = json.load(f) + json_mods = json.load(f) + for mod in json_mods: + config["game"]["mods"].append(mod) f = open(CONFIG_GENERATED, "w") json.dump(config, f, indent=4) From bc9c1514688adbae43689c04f90a64e91644f924 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Mon, 30 May 2022 23:41:18 +0200 Subject: [PATCH 07/16] Use dedicated volume for workshop --- Dockerfile | 2 ++ README.md | 1 + docker-compose.yml | 1 + launch.py | 1 + 4 files changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index f06b766..ccb70ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,6 +41,7 @@ ENV ARMA_PROFILE=/home/profile ENV ARMA_BINARY="./ArmaReforgerServer" ENV ARMA_PARAMS="" ENV ARMA_MAX_FPS=120 +ENV ARMA_WORKSHOP_DIR=/reforger/workshop ENV SERVER_REGION="EU" ENV SERVER_ID="" @@ -72,6 +73,7 @@ WORKDIR /reforger VOLUME /steamcmd VOLUME /home/profile VOLUME /reforger/Configs +VOLUME /reforger/workshop EXPOSE 2001/udp EXPOSE 17777/udp diff --git a/README.md b/README.md index e957d1d..1e76f2c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ An Arma Reforger dedicated server. Updates to the latest version every time it i -p 2001:2001/udp \ -v path/to/configs:/reforger/Configs \ -v path/to/profiles:/home/profile \ + -v path/to/workshop:/reforger/workshop \ -e SERVER_REGION="EU" \ -e SERVER_HOST_REGISTER_ADDRESS="public ip" \ -e GAME_NAME="My Docker Reforger Server" \ diff --git a/docker-compose.yml b/docker-compose.yml index 356cba4..20a0272 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ services: volumes: - ./reforger/configs:/reforger/Configs - ./reforger/profile:/home/profile + - ./reforger/workshop:/reforger/workshop environment: - SERVER_REGION=EU # or other ISO 3166-1 alpha-2 code - SERVER_HOST_REGISTER_ADDRESS=public-ip diff --git a/launch.py b/launch.py index 3e431c0..aca7b8c 100644 --- a/launch.py +++ b/launch.py @@ -144,6 +144,7 @@ def bool_str(text): "-nothrow", f"-maxFPS {os.environ['ARMA_MAX_FPS']}", f"-profile {os.environ['ARMA_PROFILE']}", + f"-addonDownloadDir {os.environ['ARMA_WORKSHOP_DIR']}" os.environ["ARMA_PARAMS"], ] ) From 7a106257fd126bb27f3261a05dc8458927eaef51 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Tue, 31 May 2022 14:41:49 +0200 Subject: [PATCH 08/16] Allow specifying mod version in GAME_MOD_IDS_LIST --- launch.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/launch.py b/launch.py index aca7b8c..3d31b56 100644 --- a/launch.py +++ b/launch.py @@ -112,18 +112,25 @@ def bool_str(text): os.environ["GAME_PROPS_NETWORK_VIEW_DISTANCE"] ) if env_defined("GAME_MODS_IDS_LIST"): - reg = re.compile("^[A-Z0-9,]+$") + reg = re.compile("^[A-Z0-9,=.]+$") if not reg.match(str(os.environ["GAME_MODS_IDS_LIST"])): print("Illegal characters in GAME_MODS_IDS_LIST env") sys.exit(1) - mod_ids = os.environ["GAME_MODS_IDS_LIST"].split(",") - for mod in mod_ids: - config["game"]["mods"].append( - { - "modId": mod, - "name": "", - } - ) + mods = str(os.environ["GAME_MODS_IDS_LIST"]).split(",") + mods[:] = [mod for mod in mods if mod] # Remove empty items form list + for mod in mods: + mod_details = mod.split("=") + assert 0 < len(mod_details) < 3, f"{mod} mod not defined properly" + mod_config = {"modId": mod_details[0]} + if len(mod_details) == 2: + reg = re.compile("^\d\.\d\.\d$") + if not reg.match(mod_details[1]): + print( + f"Mod version of '{mod_details[0]}' does not match the version pattern" + ) + sys.exit(1) + mod_config["version"] = mod_details[1] + config["game"]["mods"].append(mod_config) if env_defined("GAME_MODS_JSON_FILE_PATH"): with open(os.environ["GAME_MODS_JSON_FILE_PATH"]) as f: json_mods = json.load(f) @@ -144,7 +151,7 @@ def bool_str(text): "-nothrow", f"-maxFPS {os.environ['ARMA_MAX_FPS']}", f"-profile {os.environ['ARMA_PROFILE']}", - f"-addonDownloadDir {os.environ['ARMA_WORKSHOP_DIR']}" + f"-addonDownloadDir {os.environ['ARMA_WORKSHOP_DIR']}", os.environ["ARMA_PARAMS"], ] ) From b3cae9ad34ca7b72f72950c8b61744f256b4e839 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Tue, 31 May 2022 14:59:56 +0200 Subject: [PATCH 09/16] Adjust Dockerfile line reference in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e76f2c..caf061b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Simply check-out / copy [the provided docker-compose.yml](docker-compose.yml) an ## Parameters -Check [the Dockerfile](Dockerfile#L32-L66), more docs will come later. +Check [the Dockerfile](Dockerfile#L32-L67), more docs will come later. ### Configs From 92d7b733344e4b768c54b550fc276e2dbc4fd507 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Tue, 31 May 2022 15:12:24 +0200 Subject: [PATCH 10/16] Compile regex outside the loop, change if/sys.exit to assert --- launch.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/launch.py b/launch.py index 3d31b56..7e45a06 100644 --- a/launch.py +++ b/launch.py @@ -113,22 +113,16 @@ def bool_str(text): ) if env_defined("GAME_MODS_IDS_LIST"): reg = re.compile("^[A-Z0-9,=.]+$") - if not reg.match(str(os.environ["GAME_MODS_IDS_LIST"])): - print("Illegal characters in GAME_MODS_IDS_LIST env") - sys.exit(1) + assert reg.match(str(os.environ["GAME_MODS_IDS_LIST"])), "Illegal characters in GAME_MODS_IDS_LIST env" mods = str(os.environ["GAME_MODS_IDS_LIST"]).split(",") mods[:] = [mod for mod in mods if mod] # Remove empty items form list + reg = re.compile("^\d\.\d\.\d$") for mod in mods: mod_details = mod.split("=") assert 0 < len(mod_details) < 3, f"{mod} mod not defined properly" mod_config = {"modId": mod_details[0]} if len(mod_details) == 2: - reg = re.compile("^\d\.\d\.\d$") - if not reg.match(mod_details[1]): - print( - f"Mod version of '{mod_details[0]}' does not match the version pattern" - ) - sys.exit(1) + assert reg.match(mod_details[1]), f"{mod} mod version does not match the pattern" mod_config["version"] = mod_details[1] config["game"]["mods"].append(mod_config) if env_defined("GAME_MODS_JSON_FILE_PATH"): From 5e9bb30117df74db1d47f14736953a20f7b22f64 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Tue, 31 May 2022 15:54:27 +0200 Subject: [PATCH 11/16] Remove unused sys import, formatting changes, add Mods README.md entry --- README.md | 21 +++++++++++++++++++++ launch.py | 9 ++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index caf061b..f662fa0 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,24 @@ Check [the Dockerfile](Dockerfile#L32-L67), more docs will come later. By default the configs are generated from the ENV variables in the dockerfile. After the first run the file can be expanded with additional options manually, but the fields will always be overwritten by the ENV variables. Alternatively, change the `ARMA_CONFIG` variable to a file present in the `Configs` volume. It will be used without modification. + +### Mods + +Workshop mods can be defined in two ways. You can use both or either of those. +- via GAME_MODS_IDS_LIST variable as a comma separated list of IDs, with an optional version, for example +```sh +-e GAME_MODS_IDS_LIST="5965770215E93269=1.0.6,5965550F24A0C152" +``` +- via GAME_MODS_JSON_FILE_PATH variable, as a JSON file that contains array of mod objects, for example +```sh +-v ${PWD}/mods_file.json:/mods_file.json +-e GAME_MODS_JSON_FILE_PATH="/mods_file.json" +``` +```json +[ + { + "modId": "597706449575D90B", + "version": "1.1.1" + } +] +``` diff --git a/launch.py b/launch.py index 7e45a06..6a0c12d 100644 --- a/launch.py +++ b/launch.py @@ -3,7 +3,6 @@ import random import re import subprocess -import sys CONFIG_GENERATED = "/reforger/Configs/docker_generated.json" @@ -113,7 +112,9 @@ def bool_str(text): ) if env_defined("GAME_MODS_IDS_LIST"): reg = re.compile("^[A-Z0-9,=.]+$") - assert reg.match(str(os.environ["GAME_MODS_IDS_LIST"])), "Illegal characters in GAME_MODS_IDS_LIST env" + assert reg.match( + str(os.environ["GAME_MODS_IDS_LIST"]) + ), "Illegal characters in GAME_MODS_IDS_LIST env" mods = str(os.environ["GAME_MODS_IDS_LIST"]).split(",") mods[:] = [mod for mod in mods if mod] # Remove empty items form list reg = re.compile("^\d\.\d\.\d$") @@ -122,7 +123,9 @@ def bool_str(text): assert 0 < len(mod_details) < 3, f"{mod} mod not defined properly" mod_config = {"modId": mod_details[0]} if len(mod_details) == 2: - assert reg.match(mod_details[1]), f"{mod} mod version does not match the pattern" + assert reg.match( + mod_details[1] + ), f"{mod} mod version does not match the pattern" mod_config["version"] = mod_details[1] config["game"]["mods"].append(mod_config) if env_defined("GAME_MODS_JSON_FILE_PATH"): From 989bafa8908fdefe95471a87a919e7d84ead93f0 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Tue, 31 May 2022 19:32:10 +0200 Subject: [PATCH 12/16] Fix PEP8 W605, add -addonsDir startup param --- launch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/launch.py b/launch.py index 6a0c12d..d4f4393 100644 --- a/launch.py +++ b/launch.py @@ -111,13 +111,13 @@ def bool_str(text): os.environ["GAME_PROPS_NETWORK_VIEW_DISTANCE"] ) if env_defined("GAME_MODS_IDS_LIST"): - reg = re.compile("^[A-Z0-9,=.]+$") + reg = re.compile(r"^[A-Z\d,=.]+$") assert reg.match( str(os.environ["GAME_MODS_IDS_LIST"]) ), "Illegal characters in GAME_MODS_IDS_LIST env" mods = str(os.environ["GAME_MODS_IDS_LIST"]).split(",") mods[:] = [mod for mod in mods if mod] # Remove empty items form list - reg = re.compile("^\d\.\d\.\d$") + reg = re.compile(r"^\d\.\d\.\d$") for mod in mods: mod_details = mod.split("=") assert 0 < len(mod_details) < 3, f"{mod} mod not defined properly" @@ -149,6 +149,7 @@ def bool_str(text): f"-maxFPS {os.environ['ARMA_MAX_FPS']}", f"-profile {os.environ['ARMA_PROFILE']}", f"-addonDownloadDir {os.environ['ARMA_WORKSHOP_DIR']}", + f"-addonsDir {os.environ['ARMA_WORKSHOP_DIR']}", os.environ["ARMA_PARAMS"], ] ) From b1bc63a285b8838fc4f522d8cf21385e20c9aab4 Mon Sep 17 00:00:00 2001 From: BrettMayson Date: Fri, 10 Jun 2022 06:16:25 -0600 Subject: [PATCH 13/16] Update README.md --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f662fa0..73e217c 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,24 @@ Alternatively, change the `ARMA_CONFIG` variable to a file present in the `Confi ### Mods Workshop mods can be defined in two ways. You can use both or either of those. -- via GAME_MODS_IDS_LIST variable as a comma separated list of IDs, with an optional version, for example + +#### GAME_MODS_IDS_LIST + +a comma separated list of IDs, with an optional version, for example + ```sh -e GAME_MODS_IDS_LIST="5965770215E93269=1.0.6,5965550F24A0C152" ``` -- via GAME_MODS_JSON_FILE_PATH variable, as a JSON file that contains array of mod objects, for example + +#### GAME_MODS_JSON_FILE_PATH + +path to a JSON file that contains array of mod objects, for example + ```sh -v ${PWD}/mods_file.json:/mods_file.json -e GAME_MODS_JSON_FILE_PATH="/mods_file.json" ``` + ```json [ { From 55a90de7cf94fe8e2acf894527a816bde5392915 Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:19:06 +0200 Subject: [PATCH 14/16] Apply suggestions from code review Co-authored-by: jonpas --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73e217c..a13ffaa 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Workshop mods can be defined in two ways. You can use both or either of those. #### GAME_MODS_IDS_LIST -a comma separated list of IDs, with an optional version, for example +A comma separated list of IDs, with an optional version. ```sh -e GAME_MODS_IDS_LIST="5965770215E93269=1.0.6,5965550F24A0C152" @@ -49,7 +49,7 @@ a comma separated list of IDs, with an optional version, for example #### GAME_MODS_JSON_FILE_PATH -path to a JSON file that contains array of mod objects, for example +Path to a JSON file that contains array of mod objects. ```sh -v ${PWD}/mods_file.json:/mods_file.json From 2a059d5bd40e5a82c724502893d0e7590ccd015d Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Fri, 22 Sep 2023 18:37:55 +0200 Subject: [PATCH 15/16] Validate mods json file for modId existance, extract only valid keys to a mod config --- launch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/launch.py b/launch.py index e2547cd..f9a040b 100644 --- a/launch.py +++ b/launch.py @@ -134,7 +134,10 @@ def bool_str(text): if env_defined("GAME_MODS_JSON_FILE_PATH"): with open(os.environ["GAME_MODS_JSON_FILE_PATH"]) as f: json_mods = json.load(f) + allowed_keys = ["modId", "name", "version"] for mod in json_mods: + assert "modId" in mod, f"Entry in GAME_MODS_JSON_FILE_PATH file does not contain modId: {mod}" + mod = {key: mod[key] for key in allowed_keys if key in mod} # Extract only valid config keys config["game"]["mods"].append(mod) f = open(CONFIG_GENERATED, "w") From 9d994e8750917b22faf4c4210abb25a1afe7307a Mon Sep 17 00:00:00 2001 From: Simon <37269807+sdsznsk@users.noreply.github.com> Date: Wed, 1 Nov 2023 15:45:48 +0100 Subject: [PATCH 16/16] Comply with lint - rename var names in json mods logic to be more clear --- launch.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/launch.py b/launch.py index fd914d1..052b661 100644 --- a/launch.py +++ b/launch.py @@ -135,10 +135,16 @@ def bool_str(text): with open(os.environ["GAME_MODS_JSON_FILE_PATH"]) as f: json_mods = json.load(f) allowed_keys = ["modId", "name", "version"] - for mod in json_mods: - assert "modId" in mod, f"Entry in GAME_MODS_JSON_FILE_PATH file does not contain modId: {mod}" - mod = {key: mod[key] for key in allowed_keys if key in mod} # Extract only valid config keys - config["game"]["mods"].append(mod) + for provided_mod in json_mods: + assert ( + "modId" in provided_mod + ), f"Entry in GAME_MODS_JSON_FILE_PATH file does not contain modId: {provided_mod}" + valid_mod = { + key: provided_mod[key] + for key in allowed_keys + if key in provided_mod + } # Extract only valid config keys + config["game"]["mods"].append(valid_mod) f = open(CONFIG_GENERATED, "w") json.dump(config, f, indent=4)