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

Hermetic python #663

Closed malt3 closed 1 year ago

malt3 commented 1 year ago

I'm trying to use this ruleset to bundle tar files. On systems without python installed, the use of rules_pkg fails:

ERROR: /home/malte/bazel-examples/hello_microservice/BUILD.bazel:32:8: Writing: bazel-out/k8-fastbuild/bin/hello_microservice/asset_tar.tar failed: (Exit 127): build_tar failed: error executing command (from target //hello_microservice:asset_tar) bazel-out/k8-opt-exec-2B5CBBC6/bin/external/rules_pkg/pkg/private/tar/build_tar '--output=bazel-out/k8-fastbuild/bin/hello_microservice/asset_tar.tar' '--mode=0644' '--owner=0.0' '--owner_name=.' ... (remaining 3 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
/usr/bin/env: 'python3': No such file or directory

I understand that this project requires python, however I was wondering how to handle cases where python3 is not preinstalled on the host executing bazel build. Can users provide a hermetic, pre-registered python toolchain as described in https://github.com/bazelbuild/rules_python?

nacl commented 1 year ago

Yes, this should be possible. Note that there are likely cases where you need to a system python instance set up in your environment for the python scripts themselves to be runnable. https://github.com/bazelbuild/bazel/issues/8685 and https://bazel.build/reference/be/python#py_runtime.stub_shebang may be good starting points for reading more about this.

All this being said, this is almost certainly not related to rules_pkg. If you find evidence that is the case, feel free to reopen this ticket.

loeffel-io commented 1 year ago

for me it wants python2

load("@rules_pkg//:pkg.bzl", "pkg_tar")

pkg_tar(
    name = "jsonnet",
    srcs = ["//:jsonnet"],
    package_dir = "/usr/local/bin",
)
aiuto commented 1 year ago

FWIW... that should beload("@rules_pkg//pkg:tar.bzl", "pkg_tar") for the current release.