bazel-contrib / rules_oci

Bazel rules for building OCI containers
Apache License 2.0
305 stars 159 forks source link

best way to install a python wheel to the image with `oci_image` #710

Closed dayeol closed 1 month ago

dayeol commented 1 month ago

Hello,

I have been struggling with this for a while, and still haven't figured out the way. one of my genrule will generate a python wheel, that needs to be installed in a container image. (Note that I wasn't able to use py_wheel because this is jupyterlab extension with a whole bunch of their custom tools)

genrule(
  name = "wheel",
  srcs = glob(["**/*.py"]),
  cmd = ...
  outs = ["mypkg-0.0.0-py3-none-any.whl"],
)

oci_image(
  name = "image",
  baze = "@python_image_linux_amd64",
)

What I want is just the image that is being build have this custom wheel installed, as if I did the following in my dockerfile.

COPY mypkg-0.0.0-py3-none-any.whl ./
RUN pip install mypkg-0.0.0-py3-none-any.whl

I believe this RUN is still hermetic, but I was not able to figure out what's the best way. I was thinking about using pkg_tar, but this wheel has multiple different destinations which will make things so complicated.

Should I just bring back container_run_and_commitand forget about it?

Any advise would be appreciated!

thesayyn commented 1 month ago

There is a rule in rules_py that allows you to extract a wheel into a directory, you can use that https://github.com/aspect-build/rules_py/blob/781650cc0913728906160ae778918252e86a008d/py/tests/virtual/django/BUILD.bazel#L7-L11 in combination with tar rule to put contents of a wheel into a layer.

dayeol commented 1 month ago

Thank you!

I was able to temporarily fix it by using some init scripts in the image. I will try to unpack the wheel when i get time. I do think some new pkg rule would be great to have though.