Shrink container image: multi-stage build, drop uv from runtime #44
Labels
No labels
bug
contribution welcome
duplicate
enhancement
good first issue
help wanted
invalid
question
upstream
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Reference
marvin8/fedinesia#44
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The published container image carries unnecessary weight:
uvbinary is present at runtime but only needed at build time/distwheel files remain in the image after installationentry-point.shcallsuv run fedinesiawhich forcesuvinto the runtimeSwitching to a multi-stage build with
python:3.13-slim-bookwormas the final stage removes bothuvand the wheel files from the published image. Pre-compiling bytecode (UV_COMPILE_BYTECODE=1) is a free bonus for faster cold starts.Findings
python:3.13-slim-bookworm+ uv binary copied in viaCOPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv. SettingUV_PYTHON_PREFERENCE=only-systemensures uv uses the image's own Python 3.13 rather than downloading a managed one.python:3.13-slim-bookwormbase — Python is at the same path in both stages so the venv symlinks are valid without any fixup.entry-point.sh: swapuv run fedinesiafor/run/.venv/bin/fedinesia. The installed console-script uses the venv's shebang directly, no activation needed.UV_COMPILE_BYTECODE=1pre-generates.pycfiles in the builder so the final image has them ready.chmod +x .venv/bin/activate(entry-point never sources it) andls /distdebug line.Plan of attack
Rewrite
Containerfileas two-stage build, updateentry-point.sh. One commit on branchfix/issue-41-42-container-fixes(will be included in PR #43 which already fixes #41 and #42).