Add container support: configurable web-UI bind address + Dockerfile#113
Merged
Conversation
WebUserInterface hardcodes host="127.0.0.1" by default, which is unreachable from outside its own network namespace (e.g. from a reverse proxy in a sibling container). UserInterfaceFactory's WEB branch now reads FISHE_WEB_HOST/FISHE_WEB_PORT (defaulting to the existing 127.0.0.1:8000, so behavior is unchanged for anyone not setting them) and threads them into WebUserInterface's existing host/port constructor params. Also adds a Dockerfile (python:3.12-slim, stdlib only, non-root user) that runs examples/web_app.py with FISHE_WEB_HOST=0.0.0.0 so the web front-end is reachable from outside the container. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR makes the web UI runnable in containerized/reverse-proxied deployments by letting the WEB UI bind address/port be configured via environment variables, and adds a minimal Docker image to run the web front-end.
Changes:
- Plumbs
FISHE_WEB_HOST/FISHE_WEB_PORTthroughUserInterfaceFactorywhen creatingWebUserInterface. - Updates
examples/web_app.pyto print the configured bind address/port and documents the env var mechanism. - Adds a
Dockerfilethat runs the web app as a non-root user and pre-creates/app/datafor writable saves/volumes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/ui/test_userInterfaceFactory.py |
Adds WEB UI factory tests (default host + env override behavior). |
src/ui/userInterfaceFactory.py |
Reads FISHE_WEB_HOST / FISHE_WEB_PORT and passes them into WebUserInterface. |
examples/web_app.py |
Updates startup messaging and docs to reflect configurable bind settings. |
Dockerfile |
Provides a container image for running the web UI with 0.0.0.0:8000 defaults and non-root execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+43
to
+47
| host = os.environ.get("FISHE_WEB_HOST", "127.0.0.1") | ||
| port = int(os.environ.get("FISHE_WEB_PORT", "8000")) | ||
| return WebUserInterface( | ||
| currentPrompt, timeService, player, host=host, port=port | ||
| ) |
Comment on lines
+70
to
+72
| """Test factory creates a web UI bound to 127.0.0.1:8000 by default, | ||
| matching WebUserInterface's own defaults, when no FISHE_WEB_HOST/ | ||
| FISHE_WEB_PORT override is set.""" |
Member
Author
|
@copilot address comments |
- Wrap int() conversion of FISHE_WEB_PORT in a try/except and re-raise with a descriptive message pointing to the env var name - Add test_factory_create_web_ui_invalid_port to cover the error path - Fix test_factory_create_web_ui_default_bind docstring: it tested the host default with an overridden ephemeral port (0), not 127.0.0.1:8000
Contributor
Both reviewer comments addressed in commit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two changes needed to run FishE's web front-end in a Docker container behind a reverse proxy (Traefik), for deployment in
Stephenson-Software/gateway:WebUserInterface.__init__already acceptshost/portparams, but they were never plumbed up throughUserInterfaceFactory.create_user_interface'sWEBbranch, which called it with no override — always binding the hardcoded default127.0.0.1:8000. Inside a container on a bridge network, a process bound to127.0.0.1is unreachable from a sibling container (e.g. a reverse proxy), so this makes theWEBbranch readFISHE_WEB_HOST/FISHE_WEB_PORTenv vars, defaulting to the existing127.0.0.1:8000so behavior is unchanged for anyone not setting them.Dockerfile(python:3.12-slim, stdlib-only — no pygame, matching the web front-end's own "no extra dependencies" footprint) that runsexamples/web_app.pywithFISHE_WEB_HOST=0.0.0.0baked in viaENV, and creates/app/data(theSaveFileManagerdefault save directory, resolved relative to the process cwd) owned by a non-root user so a volume mounted over it stays writable.examples/web_app.py's startup print now reflects the actual host/port instead of a hardcoded string.Test plan
python3 -m compileall -q src testsSDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy python3 -m pytest --verbose -vv --cov=src --cov-report=term-missing --cov-report=xml:cov.xml— 327 passed,userInterfaceFactory.pyat 100% coverageblack/autoflakerun locally; only the files actually touched by this change are included in the diff (pre-existing formatting drift elsewhere in the repo was reverted, out of scope for this PR)FishE(interfaceType=UIType.WEB)withFISHE_WEB_HOST=0.0.0.0 FISHE_WEB_PORT=8123and confirmed the server bound0.0.0.0andGET /statereturned 200 with the expected JSON🤖 Generated with Claude Code