Skip to content

Move pip install into dedicated builder stage - #408

Closed
lightswitch05 wants to merge 1 commit into
home-assistant:masterfrom
lightswitch05:feature/pip-builder-stage
Closed

lightswitch05 wants to merge 1 commit into
home-assistant:masterfrom
lightswitch05:feature/pip-builder-stage

Conversation

@lightswitch05

Copy link
Copy Markdown
Contributor

Why

#343 introduced isolated builder stages for ssocr, libcec, PicoTTS, and Telldus, using COPY --link to merge them into the final image. The --link flag 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-builder stage for Python packages, but it used pip 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-image action, which uses BuildKit with mode=max layer 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-builder stage that installs Python packages using --prefix=/opt/pip-packages (instead of --user), then COPY --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.txt change triggers only the pip-builder stage; 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: true and cache-image-tag: latest explicit in the builder workflow, so caching intent is visible rather than implied by action defaults.

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.
@lightswitch05

Copy link
Copy Markdown
Contributor Author

I just realized why cache isn't working like I had thought with the original PR. FROM ${BUILD_FROM} is used for all the builder stages. If base changes (which is the main reason to re-build this image) - then all the builder stage caches are thrown away too. With that realization, I don't think this PR adds any value.

@lightswitch05
lightswitch05 deleted the feature/pip-builder-stage branch May 23, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant