Move pip install into dedicated builder stage - #408
Closed
lightswitch05 wants to merge 1 commit into
Closed
lightswitch05 wants to merge 1 commit into
lightswitch05 wants to merge 1 commit into
Conversation
Installs Python packages via --prefix=/opt/pip-packages in an isolated builder stage, then COPY --link into the final image. This enables independent layer caching so a requirements.txt change does not invalidate unrelated builder stages (ssocr, libcec, picotts, telldus), and vice versa. Also makes GHA cache and cache-image-tag explicit in the builder workflow.
Contributor
Author
|
I just realized why cache isn't working like I had thought with the original PR. |
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.
Why
#343 introduced isolated builder stages for ssocr, libcec, PicoTTS, and Telldus, using
COPY --linkto merge them into the final image. The--linkflag decouples each COPY from the parent layer chain, so a change to the base image or any other stage does not invalidate the cached result of unrelated stages — each builder is independently reusable across builds.That PR also attempted a
pip-install-builderstage for Python packages, but it usedpip install --user, which puts packages in/root/.local/rather than/usr/local/lib/python*/site-packages/where Home Assistant expects them. That part was reverted in #358.#401 migrated the workflow to the new
build-imageaction, which uses BuildKit withmode=maxlayer caching backed by GitHub Actions cache. This is what actually makes the multi-stage cache reuse from #343 pay off at CI time — every builder stage's layers are captured and reused across workflow runs.What
Adds a
pip-builderstage that installs Python packages using--prefix=/opt/pip-packages(instead of--user), thenCOPY --links the result into/usr/local/in the final image — landing packages at/usr/local/lib/python*/site-packages/exactly where they were before.This follows the same pattern already used for ssocr, libcec, PicoTTS, and Telldus. With this in place, a
requirements.txtchange triggers only thepip-builderstage; ssocr, libcec, picotts, and telldus remain cache hits. Equally, a version bump in any of those builders leaves the pip layer untouched.Also makes
cache-gha: trueandcache-image-tag: latestexplicit in the builder workflow, so caching intent is visible rather than implied by action defaults.