Add `strip_prefix` parameter to `py_image_layer`
By default, bazel lays out files using the target name as the root for all runfiles. For example, the target //a/b/c:my_bin has its runfiles directory located at $BAZEL_ROOT/a/b/c/my_bin.runfiles/. When placed into an oci_image this becomes /a/b/c/my_bin.runfiles/.
The problem with the above is that it prevents us from sharing layers between separate images. Even if no layer_groups are provided, at a minimum the contents of the interpreter layer are identical across images, but can't be shared because the path prefixes of the files are different.
The primary change in this PR is to introduce a strip_prefix option to the py_image_layer macro that allows us to remove prefixes from the directories laid out in the image. Combined with the existing root option, we can align directory paths across images and produce identical layer hashes.
Also changes the template strings to use named replacement syntax, for readability.
Changes are visible to end-users: no (default parameter value produces previous behavior)
Test plan
- New test cases added
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
Jimmy Tanner seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.
Test
1 test target passed
Targets
//docs:update_4_test [k8-fastbuild] 103ms
Total test execution time was 103ms. 28 tests (96.6%) were fully cached saving 54s.
CC @thesayyn
TODO: Rework this, potentially as part of replacing the AWK-based filtering.
Closing; need to revisit the concept.