dockerizing bazel targets

141 views
Skip to first unread message

Alex Flint

unread,
Nov 19, 2017, 8:49:51 PM11/19/17
to bazel-discuss
At my company we use bazel to build a large c++ application. We would then like to ship one target built using bazel into production by creating a minimal docker image containing that target. Our targets depend on many shared libraries and configuration files, and these are all spelled out bazel build files, so I would like to figure out what are the dependencies of a target and create a docker image containing them together with the target.

Does anyone have any suggestions/examples on how I might do this?

I am aware of rules_docker, but this does not really (afaik) solve my problem: my goal is not to build the docker image itself using bazel but to use bazel's understanding of my target's dependencies to ship everything needed (and nothing that isn't) in the docker image.

Currently we are building a docker image containing _all_ bazel outputs (targets + libraries) but this is unnecessarily large.

Damien Martin-Guillerez

unread,
Nov 20, 2017, 7:23:18 AM11/20/17
to Alex Flint, matt...@google.com, b...@benjamin.pe, bazel-discuss
I think +Matthew Moore want to do something along those line and it also relates to +Benjamin Peterson effort to package runfiles of a binary.

TL;DR: you need to package all the runfiles of a binary but it can be hard to know which are the correct files.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/9d93302e-a817-4f97-a189-dc383d975d22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Benjamin Peterson

unread,
Nov 21, 2017, 2:40:00 AM11/21/17
to Damien Martin-Guillerez, Alex Flint, matt...@google.com, bazel-discuss
Yes, I would very much like to see the ability to write packaging rules
that handle runfiles trees properly (i.e., actually include them). The
main difficulty in doing that today is that Skylark doesn't expose
enough information about runfiles trees [1]. I'm hoping the Skylark API
committee will soon be able to look at my proposal [2] to remedy this.

[1] https://github.com/bazelbuild/bazel/issues/3880
[2] https://groups.google.com/d/msg/bazel-dev/sH9gXsL_99g/GW-ipg_uCgAJ

On Mon, Nov 20, 2017, at 04:23, Damien Martin-Guillerez wrote:
> I think +Matthew Moore <matt...@google.com> want to do something along
> those line and it also relates to +Benjamin Peterson <b...@benjamin.pe>
> > <https://groups.google.com/d/msgid/bazel-discuss/9d93302e-a817-4f97-a189-dc383d975d22%40googlegroups.com?utm_medium=email&utm_source=footer>
> > .

Matthew Moore

unread,
Nov 27, 2017, 10:20:22 AM11/27/17
to Benjamin Peterson, Damien Martin-Guillerez, Alex Flint, bazel-discuss, Dan Lorenc
This is essentially the goal of the lang_image rules.

If you have an example where this isn't WAI, I'd appreciate an example / GH issue.

thanks,
-M





--
Matthew Moore
Container Development Uber-TL
Developer Infrastructure @ Google

Benjamin Peterson

unread,
Nov 28, 2017, 1:27:04 AM11/28/17
to Matthew Moore, Damien Martin-Guillerez, Alex Flint, bazel-discuss, Dan Lorenc
Yes, it's bit obscure. Bazel lets you create arbitrary aliases for
artifacts in the runfiles tree and these cannot be inspected through
skylark.

As an example, it's not possible to write Skylark that can correctly
package the runfiles tree this rule class:

def example_impl(ctx):
ctx.actions.file(output=ctx.outputs.executable, executable=True,
content='hello')
return struct(
ctx.runfiles(symlinks={'example-runfile' :
ctx.outputs.executable}),
)

example = rule(
implementation = example_impl,
executable = True,
)

The builtin Bazel rules don't use this symlinks feature except in arcane
situations, so you're probably mostly in the clear.

On Mon, Nov 27, 2017, at 07:20, Matthew Moore wrote:
> This is essentially the goal of the lang_image
> <https://github.com/bazelbuild/rules_docker#language-rules> rules.
> > > > email to bazel-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages