fix: reduce docker build image size by over 13x #8
+10
−19
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 current SAM image is unnecessarily large, leaving room for improvement. Below is a comparison of the resulting Docker images before and after the Dockerfile optimization:
Premise
Given this, Python 3.9 is the minimum viable version. However, setting Python 3.13 as the default makes more sense, allowing users to override the build argument if needed.
Approach
We'll leverage the official uv Docker images, which bundle both uv and Python. This eliminates the need to install them manually, enabling seamless selection of any uv and Python version. By default, we'll use the latest uv binary and Python 3.13.
To simplify customization, we could introduce a
uvVersion
property in thePythonFunction
construct. This would allow users to override the uv version without touchingbuildArgs
in thebundling
property.Simplifications
UV_CACHE_DIR
, defaulting to$HOME/.cache/uv
instead of setting a custom cache directory.Results
These changes reduce the Docker image size from over 2GB to just 156MB, while retaining flexibility to select any Python and uv version directly from the base image.