From 6fd19d769b27fc56b2383f95ff972bf37e060542 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Mon, 9 Feb 2026 12:34:56 -0500 Subject: [PATCH] Add a docker container solution --- .dockerignore | 17 +++++++++++++++++ Dockerfile | 28 ++++++++++++++++++++++++++++ compose.yml | 13 +++++++++++++ src/mudlib/server.py | 8 +++++--- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe81bfd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +__pycache__ +*.pyc +.git +.gitignore +.worktrees +.testmondata +repos +build +data +*.egg-info +.ruff_cache +.pytest_cache +docs +tests +TODO.md +DREAMBOOK.md +dbzfe.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6b24f84 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3.13-slim + +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ + +# frotz provides dfrotz (z-machine interpreter for interactive fiction) +RUN apt-get update \ + && apt-get install -y --no-install-recommends frotz \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# install deps first (better layer caching) +COPY pyproject.toml ./ +# replace local-path telnetlib3 dep with PyPI version for container build +RUN sed -i 's|telnetlib3 @ file:///home/jtm/src/telnetlib3|telnetlib3>=2.3.0|' pyproject.toml \ + && uv sync --no-dev --no-install-project + +# copy project source and content +COPY src/ src/ +COPY content/ content/ +COPY worlds/ worlds/ +RUN uv sync --no-dev + +EXPOSE 6789 + +ENV MUD_HOST=0.0.0.0 + +CMD ["uv", "run", "python", "-m", "mudlib"] diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..498fc72 --- /dev/null +++ b/compose.yml @@ -0,0 +1,13 @@ +services: + mud: + build: . + ports: + - "6789:6789" + volumes: + - mud-data:/app/data + - mud-cache:/app/build + restart: unless-stopped + +volumes: + mud-data: + mud-cache: diff --git a/src/mudlib/server.py b/src/mudlib/server.py index c660d89..6d80a95 100644 --- a/src/mudlib/server.py +++ b/src/mudlib/server.py @@ -2,6 +2,7 @@ import asyncio import logging +import os import pathlib import time import tomllib @@ -43,7 +44,8 @@ from mudlib.world.terrain import World log = logging.getLogger(__name__) -PORT = 6789 +HOST = os.environ.get("MUD_HOST", "127.0.0.1") +PORT = int(os.environ.get("MUD_PORT", "6789")) TICK_RATE = 10 # ticks per second TICK_INTERVAL = 1.0 / TICK_RATE AUTOSAVE_INTERVAL = 60.0 # seconds between auto-saves @@ -414,9 +416,9 @@ async def run_server() -> None: # MUD clients like tintin++ reject CHARSET immediately via MTTS, but # telnetlib3 still waits for the full timeout. 0.5s is plenty. server = await telnetlib3.create_server( - host="127.0.0.1", port=PORT, shell=shell, connect_maxwait=0.5 + host=HOST, port=PORT, shell=shell, connect_maxwait=0.5 ) - log.info("listening on 127.0.0.1:%d", PORT) + log.info("listening on %s:%d", HOST, PORT) loop_task = asyncio.create_task(game_loop())