add function to overwrite snake config when its set as env and use smaller python alpine container as base
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM python:3.10.6-slim
|
||||
FROM python:alpine
|
||||
|
||||
# Install app
|
||||
COPY . /app
|
||||
|
||||
+3
-5
@@ -1,10 +1,8 @@
|
||||
blinker==1.7.0
|
||||
click==8.1.7
|
||||
Flask==3.0.2
|
||||
itsdangerous==2.1.2
|
||||
Flask==3.0.3
|
||||
itsdangerous==2.2.0
|
||||
Jinja2==3.1.3
|
||||
MarkupSafe==2.1.5
|
||||
numpy==1.26.4
|
||||
python-dotenv==1.0.1
|
||||
scipy==1.12.0
|
||||
Werkzeug==3.0.1
|
||||
Werkzeug==3.0.2
|
||||
|
||||
+8
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user