fix(docker): install jsonschema and copy schemas/ into the image - #134
Merged
Conversation
The image could not start. `src/fishE.py` imports jsonschema at module scope, but the Dockerfile installed nothing, on the stated premise that the game is stdlib-only. It isn't: src/fishE.py:3 from jsonschema.exceptions import ValidationError src/validation/schemaValidator.py:4 from jsonschema import validate There is no requirements.txt, and run.sh's checkDependencies() (which would have installed one) is commented out -- so .github/workflows/test.yml's `pip install pytest pytest-cov jsonschema pygame` was the only place the dependency was recorded, and the image never picked it up. A second, latent bug behind the first: the save-file readers resolve their schemas relative to the process cwd (PLAYER_SCHEMA_PATH = "schemas/player.json", cwd = /app in the image), but schemas/ was never copied in -- so every save load/write would have raised FileNotFoundError even once the import worked. Adds requirements.txt (jsonschema only; pygame stays out, since the pygame front-end imports it lazily and neither the console nor web front-end needs it), installs it in the image, and copies schemas/. Verified by reproducing the exact production traceback in a clean venv against the old layout, then re-running the fixed layout: the web front-end serves 200 on `/` (with `<title>FishE</title>`) and on `/state`, and `validate_against_schema` resolves schemas/player.json. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
The image never ran
The Dockerfile (added in #113 for containerized deployment) installs no dependencies, on the stated premise that the game is stdlib-only. That premise is false —
src/fishE.pyimportsjsonschemaat module scope, so the game cannot start without it:src/fishE.py:3—from jsonschema.exceptions import ValidationErrorsrc/validation/schemaValidator.py:4—from jsonschema import validateThis was caught when the image was deployed for real for the first time (behind
fishe.danielstephenson.dev). The container crash-looped 638 times before it was pulled:The dependency was recorded in exactly one place —
.github/workflows/test.yml'spip install pytest pytest-cov jsonschema pygame. There's norequirements.txt, andrun.sh'scheckDependencies()(which would have installed one) is commented out, so nothing propagated it to the image.A second, latent bug behind the first
Fixing only the import would have moved the failure rather than removed it. The save-file readers resolve their schemas relative to the process cwd:
cwd is
/appin the image, andschemas/was never copied in — so every save load/write would have raisedFileNotFoundError. The app would have started, served the menu, and then broken the moment a player touched a save slot.Changes
requirements.txt(new) —jsonschema>=4.0,<5.0.pygameis deliberately excluded: the pygame front-end imports it lazily, so the console and web front-ends run without it.Dockerfile— install fromrequirements.txt, copyschemas/, and drop the inaccurate "no third-party deps" comment.Verification
Reproduced and fixed against the exact file layout each Dockerfile produces, using a clean venv with no
jsonschema:python3 examples/web_app.pyModuleNotFoundError: No module named 'jsonschema'GET /200, contains<title>FishE</title>GET /state200, JSON withscreen/versionvalidate_against_schema({}, PLAYER_SCHEMA_PATH)FileNotFoundError: schemas/player.jsonValidationError, as expected for{})The
GET /check is the exact command the gateway healthcheck runs.No
src/changes, so the existing test suite is unaffected — CI installsjsonschemaexplicitly and is independent of the newrequirements.txt.