Package binaries' runfiles into a docker_build rule?

216 views
Skip to first unread message

funk...@gmail.com

unread,
Mar 10, 2017, 12:13:33 PM3/10/17
to bazel-discuss, Damien Cassan
Hi,

I am looking for a way to build docker images based on the outputs of other rules. In our case, we have some java_binary and python_binary rules that we want to put in a docker image, so we can then use the images to deploy our stack.

As much as I saw, with a simple rule, you can put outputs of another rule into the docker image. Here is a minimal example of what my package looks like:

load("@bazel_tools//tools/build_defs/docker:docker.bzl", "docker_build")

py_binary(
name = "foo",
srcs = ["foo.py"], # Hello world script
)

docker_build(
name = "server_docker",
files = [":foo"],
base = "@docker_python3//:image", # a docker_pull rule
entrypoint = ["python3", "./foo"],
)

The generated foo binary is put in the docker image, however its runfiles are not:
AssertionError: Cannot find .runfiles directory for ./foo

By changing the entrypoint to ["/bin/ls"], here is the result:
bin etc foo.py lib mnt root sbin sys usr
dev foo home media proc run srv tmp var

Am I misusing the docker_build rule or is it unsupported right now?

Regards,

Matthew Moore

unread,
Mar 10, 2017, 12:17:57 PM3/10/17
to funk...@gmail.com, bazel-discuss, Damien Cassan, Steren Giannini (via Google Sites), Doug Greiman
You want to use a par_binary rule to package everything up: https://github.com/mattmoor/bazel-glibc/blob/master/examples/BUILD#L34


--
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-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/9da07e50-3ba5-4919-b215-19c5176cf79d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matthew Moore
DI/Docker (aka Convoy)
Developer Infrastructure @ Google

funk...@gmail.com

unread,
Mar 10, 2017, 12:33:49 PM3/10/17
to bazel-discuss, funk...@gmail.com, cassa...@eisti.eu, ste...@google.com, dgre...@google.com
Thanks, it is a pretty good start for our Python team!

Is there a more generic way to include runfiles, so we can also include our java/scala .jar dependencies in the docker image? By including only the :rule.jar, we miss all dependencies.

Doug Greiman

unread,
Mar 10, 2017, 5:22:55 PM3/10/17
to funk...@gmail.com, bazel-discuss, cassa...@eisti.eu, Steren Giannini
In the .jar case, I think you want foo_deploy.jar to get a .jar file that contains all the dependencies.

In the general case, there is definitely work to be done to improve the interaction between runfiles/filegroups()/docker-xyz() rules. 

balas...@gmail.com

unread,
Jun 22, 2017, 4:53:49 AM6/22/17
to bazel-discuss, funk...@gmail.com, cassa...@eisti.eu, ste...@google.com
I'm running into the same issue with a go_binary+docker_build combination.

Is there a bug open for getting a binary's runfiles populated inside a docker_build rule? Is there some workaround (other than the obvious one of manually collecting the transitive files in the docker_build's deps)?

Thanks,
Sanjay
Reply all
Reply to author
Forward
0 new messages