bazelbuild / rules_pkg

Bazel rules for creating packages of many types (zip, tar, deb, rpm, ...)
Apache License 2.0
226 stars 175 forks source link

pkg_files -> pkg_tar -> pkg_tar loses owner/group #646

Open AustinSchuh opened 1 year ago

AustinSchuh commented 1 year ago

I'm in the process of migrating a ton of pkg_tar rules to pkg_files. I'm trying to do it incrementally to stay sane. I would expect the following two to be equivalent.

pkg_files(
    name = "shell_history",
    srcs = [
        ".zsh_history",
    ],  
    attributes = pkg_attributes(
        group = "1000",
        mode = "0600",
        user = "1000",
    ),  
    prefix = "/home/debian",
    visibility = ["//brt/vpu:__subpackages__"],
)
pkg_tar(
    name = "bin_files",
    srcs = [":shell_history"]
    deps = [":more_pkg_tar_targets"],
    symlinks = symlinks,
)

and

pkg_tar(
    name = "shell_history",
    srcs = [
        ".zsh_history",
    ],  
    mode = "0600",
    owner = "1000.1000",
    package_dir = "/home/debian",
    visibility = ["//brt/vpu:__subpackages__"],
)
pkg_tar(
    name = "bin_files",
    deps = [":more_pkg_tar_targets", ":shell_history"],
    symlinks = symlinks,
)

And finally for both:

pkg_tar(
    name = "installed_binaries",
    symlinks = { 
        "/etc/systemd/system/multi-user.target.wants/startup.service": "../startup.service",
    },  
    tags = [ 
        "no-remote",
    ],  
    deps = [ 
        ":bin_files",
    ],  
)

When I inspect bin_files.tar, I see that .zsh_history is owned by 1000.1000. Inside installed_binaries, I see it owned by 0.0. With the pkg_tar rules for all steps, I see ownership properly tracked.

aiuto commented 1 year ago

Yup. It is distinct because of historic differences in how the two were implemented.. I'm not interested in putting any more work into the deps attribute of pkg_tar, especially in the intermediate tarball case that you are describing.

The preferred usage should have been.

pkg_files(name = "shell_history", ...)
pkg_tar(
    name = "bin_files",
    deps = [":more_pkg_tar_targets",],
    symlinks = symlinks,
)
pkg_tar(
    name = "installed_binaries",
    srcs = [ ":shell_history"],
    symlinks = { 
        "/etc/systemd/system/multi-user.target.wants/startup.service": "../startup.service",
    },  
    tags = [ 
        "no-remote",
    ],  
    deps = [ 
        ":bin_files",
    ],  
)

Any work I am likely to do will be for pkg_expand. https://github.com/bazelbuild/rules_pkg/issues/355

AustinSchuh commented 1 year ago

No guarantees, but is this a "I don't want to fix this" and you'd take patches, or you don't think this should be fixed and pkg_expand should be the way to do this?