bazelbuild/rules_docker

do not flatten file paths in container_image

jmhodges opened this issue · 11 comments

See https://github.com/bazelbuild/bazel/issues/2176

This is still happening and has now gotten weirder: https://github.com/bazelbuild/bazel/issues/2176#issuecomment-364352176

It would be good for container_image's files to not just be the basename files including in the directory, but to, by default, maintain the full relative file paths.

pcj commented

I find this troubling also. Is this a bug or a feature?

pcj commented

Friendly ping. This is a problem for adoption of rules_docker.

Setting strip_prefix in tar_pkg workaround helped in my case (not to ., but to specific directory, as in my layout I needed to strip some prefix):

pkg_tar(
    name = "webfrontend-tar",
    srcs = ["//webfrontend:build"],
    mode = "0o644",
    package_dir = "/usr/share/nginx/html/",
    # Otherwise all directories are flattened:
    # <https://github.com/bazelbuild/rules_docker/issues/317>
    strip_prefix = "webfrontend/build/",
)

container_image(
    name = "webfrontend-image",
    tars = [":webfrontend-tar"],
    base = "@nginx_base//image",
    visibility = ["//visibility:public"],
)

Without strip_prefix = "webfrontend/build/", all files are flattened in webfrontend-tar.

is this still an issue? please reopen if so.

It is! I can’t reopen this issue, though

Is the workaround you found using pkg_tar noy working or otherwise problematic?

It’s problematic because it’s undocumented and unexpected. It’s really hard to understand why this happens or how to fix it without lots of googling. It’s another weird thing that you have to tell people about when they just want to try out Bazel (and there’s plenty of them, you know?)

I have updated the docs (See PR updating readme) to explain this issue. I'm closing this again as I dont think the fix for this issue is on this repo (i.e., it seems to me the issue is with pkg_tar rule). Please let me know if anyone feels there is more we can do here to reopen.

njlr commented

I find it very strange that an extra rule is required to place files in specific folders in a container_image. It seems like an extremely noisy API to me.

Perhaps something like this should be possible?

container_image(
  name = "my_image",
  base = ":nodejs",
  files = {
    "/home/runner/index.js": "//:some_node_rule",
    "/home/runner/assets/logo.png": "logo.png",
  },
)

where the key to the dictionary is the path inside the image and the value is a source file or rule

This is a really huge bug imho. This means, for example, if you have a java_binary target with relative file paths based on other targets, the implementation is no longer correct inside docker. I would strongly suggest fixing -- and would be glad to help if mainters are open to that (with some parameter like flatten that defaults to the old behavior of True to avoid breaking folks).

Okay I see that the docs suggest strip_prefix = ".", oof. this no longer appears to be a valid parameter?

okay, this works data_path = ".",