From 82259f4522c2dbac9309253617ed1f98135ddf0f Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Fri, 21 Apr 2023 11:27:48 +0200 Subject: [PATCH] Docker config --- .docker/run.sh | 12 ++++++------ .docker/settings.py | 40 ++++++++++++++++++++++++++++++++++++++++ Dockerfile | 7 +++++-- hopper/models/config.py | 4 ++-- 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 .docker/settings.py diff --git a/.docker/run.sh b/.docker/run.sh index 01f5461..b1b2c0c 100755 --- a/.docker/run.sh +++ b/.docker/run.sh @@ -1,9 +1,9 @@ #!/bin/sh -echo "Hello world!" +echo "Starting FairHopper game server" -echo "Press [CTRL+C] to stop.." -while : -do - sleep 1 -done +uvicorn \ + main:app \ + --host 0.0.0.0 \ + --port ${FAIRHOPPER_API_PORT} \ + --workers=1 diff --git a/.docker/settings.py b/.docker/settings.py new file mode 100644 index 0000000..9087854 --- /dev/null +++ b/.docker/settings.py @@ -0,0 +1,40 @@ +import os +import logging + +from hopper.models.config import ( + BoardSettings, + DebugSettings, + GameSettings, + InactivityWatchdogSettings, + Settings, + WSServerSettings, +) +from hopper.models.product import Product + +settings = Settings( + game=GameSettings(), + board=BoardSettings( + WIDTH=20, + HEIGHT=20, + OBSTACLE_COUNT=0, + ), + inacivity_watchdog=InactivityWatchdogSettings(), + purchase_timeout=5, + log_level=logging.INFO, + products=[ + Product(name="CocaCola", id="cocacola-id"), + Product(name="Pepsi", id="pepsi-id"), + Product(name="Fanta", id="fanta-id"), + Product(name="Snickers", id="snickers-id"), + Product(name="Mars", id="mars-id"), + Product(name="Burek", id="burek-id"), + ], + ws_server=WSServerSettings( + HOST="0.0.0.0", + PORT=int(os.environ.get("FAIRHOPPER_WS_PORT", 8011)), + ), + debug=DebugSettings( + PRINT_BOARD=True, + PLAYERS=[], + ), +) diff --git a/Dockerfile b/Dockerfile index f7285f0..9f9cd59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,8 @@ RUN python -m venv /venv ENV \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ + FAIRHOPPER_API_PORT=${INTERNAL_API_PORT} \ + FAIRHOPPER_WS_PORT=${INTERNAL_WS_PORT} \ PATH="/venv/bin:$PATH" RUN \ @@ -26,7 +28,8 @@ RUN \ # install python libs pip install -r requirements.txt --no-cache-dir --prefer-binary -COPY ./.docker/run.sh . -COPY ./hopper ./service +COPY ./.docker/* ./ +COPY ./hopper ./hopper +COPY ./main.py . ENTRYPOINT [ "/app/run.sh" ] diff --git a/hopper/models/config.py b/hopper/models/config.py index 9388c13..0af7fae 100644 --- a/hopper/models/config.py +++ b/hopper/models/config.py @@ -29,7 +29,7 @@ class InactivityWatchdogSettings: @dataclass class WSServerSettings: - HOST: str = "localhost" + HOST: str = "127.0.0.1" PORT: int = 8011 @@ -45,7 +45,7 @@ class Settings: board: BoardSettings inacivity_watchdog: InactivityWatchdogSettings ws_server: WSServerSettings - purchase_timeout: int = 10 # seconds + purchase_timeout: int = 10 # seconds log_level: int = logging.INFO products: List[Product] = None debug: Optional[DebugSettings] = None