Repository navigation
perf(docker): install the dev image's dependencies before the code - #217
Merged
Merged
Conversation
The dev Dockerfile copied the code in before `pip install -e .`, so any code change reinstalled every dependency, about 190 MB a time. Compose checks rebuild the image on every run. Its base, python:3.12-slim, was unpinned, so each new release of it also reran the apt-get layer, build-essential and libpq-dev, another 436 MB. Over months these copies filled Docker's build cache. The image now follows Dockerfile.production: the same pinned base image and uv, the packages uv.lock pins installed into /opt/venv (outside /app, which Compose mounts over) from pyproject.toml and uv.lock alone, then the code, then the project itself, editable, as before. No apt-get: psycopg is psycopg[binary], and every locked package has a wheel. Dev containers now get uv.lock's versions rather than the newest that pyproject.toml allows, the same as production. A dependency change needs `uv lock` before the image builds (--locked), which AGENTS.md now says. docs/sandboxed_docker_setup.md lists the images it pulls. Tested: a code change rebuilds in about 2 s, with the dependency layer cached. scripts/repo_check_compose.sh passes with the new image (1,843 tests), skipping only step 2, the GraphQL validation on the host. python, celery and the editable queueboard package resolve from /opt/venv, and psycopg uses its binary implementation. 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.
Motivation
The dev
Dockerfilecopied the code in beforepip install -e ., so any code change reinstalled every dependency, about 190 MB each time, andscripts/repo_check_compose.shrebuilds the image on every run. Its base image,python:3.12-slim, wasn't pinned, so each new release of it also reran theapt-get install build-essential libpq-devlayer, another 436 MB. Over months, one machine's Docker build cache held about 15 copies of the apt layer and dozens of the pip layer.What changes
Dockerfilenow followsDockerfile.production:uv;uv.lockpins, installed into/opt/venvfrompyproject.tomlanduv.lockalone, with uv's download cache./opt/venvis outside/app, which Compose mounts over;pip install -e .installed it, sosrc/stays on the path.apt-get: psycopg ispsycopg[binary], and every locked package has a wheel.AGENTS.mdsays so under Containers & Volumes, and that a dependency change needsuv lockbefore the image builds (--locked).docs/sandboxed_docker_setup.mdlists the images the stack now pulls.User-visible effects
None in the app. Dev containers now get
uv.lock's versions rather than the newest thatpyproject.tomlallows, the same as production. Apyproject.tomlchange withoutuv locknow failsdocker compose buildinstead of resolving afresh.Testing
python,celeryand the editablequeueboardpackage resolve from/opt/venv, and psycopg uses its binary implementation.bash scripts/repo_check_compose.shpasses, skipping only step 2, the GraphQL validation, which runs on the host (core 139, syncer 543, analyzer 606, api 28, zulip_bot 350, console 96, site_analytics 81 tests).🤖 Generated with Claude Code