PSA: Build-in-Docker: execute a build step in an arbitrary docker container

182 views
Skip to first unread message

Filip Filmar

unread,
Mar 6, 2023, 1:53:28 PM3/6/23
to bazel-discuss
Hi folks.

A while back, I asked how I could invoke a Bazel build step inside an arbitrary container, as a way to work around excessively complex setups needed for some pieces of software to be hermeticized for use in Bazel.  Typically, these are pieces of software written in Python, which pull in loads of implicit dependencies.

In the meantime, I managed to solve the issue, and factored the main pieces of my setup which is now reusable at https://github.com/filmil/bazel-rules-bid. You can follow the README.md to see how it is used, and use the sample repo to try it out yourself.

 Instead of hermeticizing the entire lot, which is a lot of work, I build a docker container instead using the 'normal' install procedures, and invoke the tool from within a container, with all bazel paths mounted in.

This allows me to pull in *any* tool that I need into a build env container and invoke it from there, with bazel being none the wiser. Compare that to the amount of work that went into making LaTeX available to Bazel the conventional way. I can either build a custom container, or I can reuse if one is available out there.

I'm sure you bazel buffs will find many better ways to do this, but I needed this at some point, and couldn't find or figure out a better way at the time. I also tried using nix, but couldn't get it to work in the time I had to finish the project off.

Thought I'd share, in case someone needs it. I couldn't find any similar approaches on teh Internets, so it may be useful to someone.

Potential downsides are needing docker as a dep, potential conflict with RBE, and any number of other things you may notice. But it did solve my issue, and that's why I hope it has some utility to others too.

Cheers,
F
Reply all
Reply to author
Forward
0 new messages