add function to overwrite snake config when its set as env and use smaller python alpine container as base

This commit is contained in:
2024-04-17 19:29:18 +02:00
parent 8c57e48f60
commit cceded8468
3 changed files with 12 additions and 10 deletions
+8 -4
View File
@@ -63,9 +63,15 @@ class Server:
def _read_json_config_or_create(self):
snake_config = read_file(self.config_file, json.load)
if not snake_config:
snake_config = self.default_snake_config
snake_config = self._override_snake_config_with_environment_variables(self.default_snake_config)
save_file(self.config_file, snake_config, callback=json.dump, indent=2, ensure_ascii=False)
return snake_config
return self._override_snake_config_with_environment_variables(snake_config)
def _override_snake_config_with_environment_variables(self, config:dict[str]):
for key in ["color", "head", "tail"]:
if os.environ.get(f"SNAKE_{key.upper()}", None):
config[key.lower()] = os.environ.get(f"SNAKE_{key.upper()}")
return config
def enable_store_game_state(self):
self.store_game_state = True
@@ -75,8 +81,6 @@ class Server:
# TIP: If you open your Battlesnake URL in a browser you should see this data
def _info(self) -> dict:
snake_config = self._read_json_config_or_create()
if os.environ.get("COLOR", None):
snake_config["color"] = os.environ.get("COLOR")
print("INFO Snake:", snake_config)
return snake_config