Skip to content

feat: declarative local_packages: for adjacent Python packages, with cache-friendly late install #602

Description

@andrinr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions