Add a docker container solution
This commit is contained in:
parent
af941b329b
commit
6fd19d769b
4 changed files with 63 additions and 3 deletions
17
.dockerignore
Normal file
17
.dockerignore
Normal file
|
|
@ -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
|
||||||
28
Dockerfile
Normal file
28
Dockerfile
Normal file
|
|
@ -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"]
|
||||||
13
compose.yml
Normal file
13
compose.yml
Normal file
|
|
@ -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:
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import time
|
import time
|
||||||
import tomllib
|
import tomllib
|
||||||
|
|
@ -43,7 +44,8 @@ from mudlib.world.terrain import World
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
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_RATE = 10 # ticks per second
|
||||||
TICK_INTERVAL = 1.0 / TICK_RATE
|
TICK_INTERVAL = 1.0 / TICK_RATE
|
||||||
AUTOSAVE_INTERVAL = 60.0 # seconds between auto-saves
|
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
|
# MUD clients like tintin++ reject CHARSET immediately via MTTS, but
|
||||||
# telnetlib3 still waits for the full timeout. 0.5s is plenty.
|
# telnetlib3 still waits for the full timeout. 0.5s is plenty.
|
||||||
server = await telnetlib3.create_server(
|
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())
|
loop_task = asyncio.create_task(game_loop())
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue