Summary
Add a build_config.local_packages: block that pip-installs a Python package from an adjacent path. It should install in the last Dockerfile layer and read the source via RUN --mount=type=bind so a change to that package doesn't invalidate the rest of the image cache.
Why is this needed?
The current pattern is:
package_data:
- ["../../../my_shared_pkg", "/tmp/my_shared_pkg"]
custom_build_steps:
- "RUN pip install /tmp/my_shared_pkg"
package_data becomes a COPY near the top of the generated Dockerfile. Editing one line in my_shared_pkg changes the COPY's input, which invalidates that layer and every layer after it. For a project that shares a small schema package across many Tesseracts, a one-line schema change forces a full rebuild of every image.
A local_packages: block can fix this two ways:
- Install in the last Dockerfile layer, so a change to the package only reruns that one layer.
- Use
RUN --mount=type=bind,source=... instead of COPY, so there is no COPY layer to invalidate at all.
Usage example
build_config:
local_packages:
- path: ../../../my_shared_pkg
# optional: editable: bool, extras: [...], position: late|early
Rendered (last layer):
RUN --mount=type=bind,source=../../../my_shared_pkg,target=/tmp/pkg \
--mount=type=cache,target=/root/.cache/pip \
pip install /tmp/pkg
Notes
position: early is for the rare case where an earlier custom_build_step needs to import the local package at build time.
- Multiple entries each become their own late layer.
- Works alongside
requirements.provider: conda.
Summary
Add a
build_config.local_packages:block that pip-installs a Python package from an adjacent path. It should install in the last Dockerfile layer and read the source viaRUN --mount=type=bindso a change to that package doesn't invalidate the rest of the image cache.Why is this needed?
The current pattern is:
package_databecomes aCOPYnear the top of the generated Dockerfile. Editing one line inmy_shared_pkgchanges the COPY's input, which invalidates that layer and every layer after it. For a project that shares a small schema package across many Tesseracts, a one-line schema change forces a full rebuild of every image.A
local_packages:block can fix this two ways:RUN --mount=type=bind,source=...instead ofCOPY, so there is no COPY layer to invalidate at all.Usage example
Rendered (last layer):
RUN --mount=type=bind,source=../../../my_shared_pkg,target=/tmp/pkg \ --mount=type=cache,target=/root/.cache/pip \ pip install /tmp/pkgNotes
position: earlyis for the rare case where an earliercustom_build_stepneeds to import the local package at build time.requirements.provider: conda.