rules_js icon indicating copy to clipboard operation
rules_js copied to clipboard

[Bug]: js_binary script launcher doesn't work with Alpine(dash) and no way to disable runfiles

Open lqc opened this issue 8 months ago • 2 comments

What happened?

I'm trying to convert an existing project into rules_js + rules_oci. The examples suggests that it should be fine to use js_binary combined with js_image_layer as input to oci_image. The problem is I wanted to use node:lts-alpine as my base image and the launcher script doesn't seem to work with Alpine's default shell dash:

18:20 $ docker run --rm -it my-image:latest
/app/my-image/main: /app/my-image/main.runfiles/_main/my-image/main.sh: line 160: syntax error: unexpected redirection

Looking into making a PR for this, but not sure how to create a test for it.

Version

Development (host) and target OS/architectures: MacOS / amd64

Output of bazel --version: aspect 5.7.2

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file:

bazel_dep(name = "bazel_skylib", version = "1.4.1") bazel_dep(name = "rules_jvm_external", version = "5.3") bazel_dep(name = "contrib_rules_jvm", version = "0.13.0") bazel_dep(name = "aspect_bazel_lib", version = "1.32.1") bazel_dep(name = "aspect_rules_js", version = "1.32.2") bazel_dep(name = "aspect_rules_ts", version = "2.0.0") bazel_dep(name = "aspect_rules_jest", version = "0.19.5") bazel_dep(name = "rules_nodejs", version = "6.0.1") bazel_dep(name = "rules_oci", version = "1.4.0")

Language(s) and/or frameworks involved:

TS, Node.js, rules_oci, Docker

How to reproduce

# You can use an empty main.js
js_binary(
    name = "main",
    data = [":compile"],
    entry_point = "main.js",
    enable_runfiles=False,
)

js_image_layer(
    name = "layers",
    binary = ":main",
    platform = "//:amd64_linux",
    root = "/app",
    visibility = ["//visibility:__pkg__"],
)

oci_image(
    name = "image",
    base = "@node-lts",
    cmd = ["/app/docs-service/assets-server/main"],
    entrypoint = ["/bin/sh"],
    tars = [
        ":layers",
    ],
)

oci_tarball(
    name = "tarball",
    image = ":image",
    repo_tags = ["syncron/cao/rnd.tools/docs-service:latest"],
)

Any other information?

The offending lines seems to be:

  • https://github.com/aspect-build/rules_js/blob/main/js/private/test/shellcheck_launcher.sh#L160 -- easy to replace with plain echo
  • https://github.com/aspect-build/rules_js/blob/main/js/private/test/shellcheck_launcher.sh#L410 -- dash doesn't support arrays

Removing --enable_runfiles from .bazelrc does nothing (launcher still generated) and trying to pass enable_runfiles=False to the rule explicitly yields an error:

	File "***/external/aspect_rules_js~1.32.2/js/defs.bzl", line 30, column 15, in js_binary
		_js_binary(
Error in js_binary: rule(...) got multiple values for parameter 'enable_runfiles'

lqc avatar Oct 14 '23 18:10 lqc

Yeah that makes sense, our shebang lines all indicate we run only under bash. Probably half the time required to fix this issue is just figuring out how we ought to test against multiple shells.

alexeagle avatar Nov 01 '23 02:11 alexeagle

Also, why do you mention runfiles here? That seems unrelated to me

alexeagle avatar Nov 01 '23 02:11 alexeagle