Repository navigation
perf(docker): uv.lock-pinned venv, ~490 MB smaller image; declare packaging - #965
Merged
Merged
Conversation
codex/version.py has imported packaging.version since 446cab8 (v2.2.10), but packaging was never a dependency and nothing in the runtime closure pulls it in. Installs only worked where something else had dragged it in: the Docker image got it from the builder's pip/poetry tooling. A fresh `uv pip install codex==2.5.1` crashes on import with ModuleNotFoundError: No module named 'packaging'. An AST scan of every import under codex/ against a runtime-only venv finds nothing else missing (icecream and schema_graph are dev-guarded). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The final image was python-debian plus `COPY --from=wheel-installer /usr/local /usr/local`, which shipped the whole nikolaik builder: node, npm, uv, poetry and pipenv (~330 MB), and replaced python-debian's own interpreter and stdlib. - Runtime deps now install into /opt/codex, a venv on python-debian's interpreter, pinned from uv.lock via `uv export` instead of re-resolved from pyproject ranges. Only that venv is copied into final. PATH gets /opt/codex/bin so `docker exec codex python` still works. - The apt install of `ruamel.yaml.clib` was parsed as a regex and installed python3-ruamel.yaml.clib plus Debian's entire python3.13. The image codec libraries were dead weight too (the Pillow and PyYAML wheels bundle their own). final installs only curl, libstdc++6 and unrar. - Bytecode is compiled at install time instead of purged. The app runs as abc, which can't write .pyc files, so every process recompiled on import: `import codex.asgi` as abc drops from 3.3 s to 1.1 s. - pycountry's gettext locales and every non-English Django/allauth/DRF locale are removed: LANGUAGE_CODE is en-us and there is no LocaleMiddleware. - A build-time smoke import fails the build, not container start, on a broken venv. arm64 image: 1,380 MB -> 889 MB. Covers and first pages of a CBR, CBZ and PDF are byte-identical to the old image's. Both platforms build. tests/test_dockerfile.py pins the apt list, the no-regex-names rule, the venv-only copy and kept bytecode. .dockerignore now admits the Dockerfile so the test runs in the CI image. Co-Authored-By: Claude Opus 5.5 <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.
Summary
codex/version.pyhas importedpackagingsince v2.2.10 but codex never declared it. A freshcodex==2.5.1PyPI install crashes on import; the Docker image only worked because the builder's tooling leaked it in. Addspackaging>=24.0./opt/codex, pinned fromuv.lock, and only that venv is copied intofinal(it used to copy the builder's whole/usr/local: node, uv, poetry, pipenv).finalinstalls onlycurl libstdc++6 unrar.ruamel.yaml.clibwas read by apt as a regex and installed Debian's whole python3.13. The image codec libs were unused because the Pillow/PyYAML wheels bundle their own.abccan't write.pyc.import codex.asgiasabcgoes from 3.3 s to 1.1 s.LANGUAGE_CODE = "en-us", noLocaleMiddleware).tests/test_dockerfile.pyguards the apt list, regex-trap names, the venv-only copy and kept bytecode..dockerignorere-admitsDockerfileso the test runs in CI.COPYlayerAbout 208 MB more (scipy/numpy/pywt via imagehash) goes away once codex moves to comicbox 5.3.0, which replaces imagehash with a bit-identical pure-Python pHash.
Test plan
make fix lint ty teston macOS (hadolint + dockerfmt included): 1580 passed, 962 frontend passedmake build-choices lint testinside the rebuiltcodex-ciimagedocker buildx build --platform linux/amd64,linux/arm64builds; the build-time smoke import passes on bothPUID/PGID:/healthis 200, a CBZ/CBR/PDF library imports, and covers and first pages are byte-identical to the old image'sAccept-Language: detests/test_dockerfile.pyfails all 4 checks against the old Dockerfile🤖 Generated with Claude Code