Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Runfiles in Docker Image not working #612

Closed
1 task
supercairos opened this issue Nov 15, 2022 · 5 comments
Closed
1 task

[Bug]: Runfiles in Docker Image not working #612

supercairos opened this issue Nov 15, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@supercairos
Copy link

What happened?

While using a js_rules inside the js_image_helper, some environement variable seems to be missing since 1.6.X

In 1.6.X:

{
  OLDPWD: '/',
  JS_BINARY__LOG_ERROR: '1',
  FEDERATION_FILE: '/config/federation.json',
  JS_BINARY__FS_PATCH_ROOTS: '/:/app/hydra-ui/img-bin.sh.runfiles',
  PATH: '/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/hydra-ui/img-bin_node_bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
  JS_BINARY__COMPILATION_MODE: 'fastbuild',
  JS_BINARY__COPY_DATA_TO_BIN: '1',
  JS_BINARY__PACKAGE: 'hydra-ui',
  JS_BINARY__NODE_WRAPPER: '/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/hydra-ui/img-bin_node_bin/node',
  JS_BINARY__TARGET_NAME: 'img-bin',
  SHLVL: '0',
  JS_BINARY__TARGET: '//hydra-ui:img-bin',
  JS_BINARY__RUNFILES: '/app/hydra-ui/img-bin.sh.runfiles',
  JS_BINARY__EXECROOT: '/',
  NODE_CONFIG_DIR: '/config',
  BAZEL_BINDIR: '.',
  JS_BINARY__LOG_PREFIX: 'aspect_rules_js[js_binary]',
  HOME: '/var/www',
  JS_BINARY__NODE_PATCHES: '/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/../aspect_rules_js/js/private/node-patches/register.js',
  JS_BINARY__LOG_FATAL: '1',
  JS_BINARY__TARGET_CPU: 'darwin_arm64',
  PWD: '/',
  JS_BINARY__WORKSPACE: 'com_shadow_cbp',
  JS_BINARY__BINDIR: 'bazel-out/darwin_arm64-fastbuild-ST-4a519fd6d3e4/bin',
  JS_BINARY__NODE_BINARY: '/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/../nodejs_linux_amd64/bin/nodejs/bin/node',
  JS_BINARY__BUILD_FILE_PATH: 'hydra-ui/BUILD',
  HOSTNAME: 'b02760d0422c',
  RUNFILES: '/app/hydra-ui/img-bin.sh.runfiles',
  JS_BINARY__PATCH_NODE_FS: '1',
  JS_BINARY__NODE_PATCHES_DEPTH: '.'
}

In 1.5.3

{
  'BASH_FUNC_runfiles_export_envvars%%': '() {  if [[ ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" && ! -d "${RUNFILES_DIR:-/dev/null}" ]]; then\n' +
    ' return 1;\n' +
    ' fi;\n' +
    ' if [[ ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then\n' +
    ' if [[ -f "$RUNFILES_DIR/MANIFEST" ]]; then\n' +
    ' export RUNFILES_MANIFEST_FILE="$RUNFILES_DIR/MANIFEST";\n' +
    ' else\n' +
    ' if [[ -f "${RUNFILES_DIR}_manifest" ]]; then\n' +
    ' export RUNFILES_MANIFEST_FILE="${RUNFILES_DIR}_manifest";\n' +
    ' else\n' +
    ' export RUNFILES_MANIFEST_FILE=;\n' +
    ' fi;\n' +
    ' fi;\n' +
    ' else\n' +
    ' if [[ ! -d "${RUNFILES_DIR:-/dev/null}" ]]; then\n' +
    ' if [[ "$RUNFILES_MANIFEST_FILE" == */MANIFEST && -d "${RUNFILES_MANIFEST_FILE%/MANIFEST}" ]]; then\n' +
    ' export RUNFILES_DIR="${RUNFILES_MANIFEST_FILE%/MANIFEST}";\n' +
    ' export JAVA_RUNFILES="$RUNFILES_DIR";\n' +
    ' else\n' +
    ' if [[ "$RUNFILES_MANIFEST_FILE" == *_manifest && -d "${RUNFILES_MANIFEST_FILE%_manifest}" ]]; then\n' +
    ' export RUNFILES_DIR="${RUNFILES_MANIFEST_FILE%_manifest}";\n' +
    ' export JAVA_RUNFILES="$RUNFILES_DIR";\n' +
    ' else\n' +
    ' export RUNFILES_DIR=;\n' +
    ' fi;\n' +
    ' fi;\n' +
    ' fi;\n' +
    ' fi\n' +
    '}',
  'BASH_FUNC_rlocation%%': '() {  if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "INFO[runfiles.bash]: rlocation($1): start" 1>&2;\n' +
    ' fi;\n' +
    ' if [[ "$1" =~ $_RLOCATION_ISABS_PATTERN ]]; then\n' +
    ' if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "INFO[runfiles.bash]: rlocation($1): absolute path, return" 1>&2;\n' +
    ' fi;\n' +
    ' echo "$1";\n' +
    ' else\n' +
    ' if [[ "$1" == ../* || "$1" == */.. || "$1" == ./* || "$1" == */./* || "$1" == "*/." || "$1" == *//* ]]; then\n' +
    ' if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "ERROR[runfiles.bash]: rlocation($1): path is not normalized" 1>&2;\n' +
    ' fi;\n' +
    ' return 1;\n' +
    ' else\n' +
    ' if [[ "$1" == \\\\* ]]; then\n' +
    ' if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "ERROR[runfiles.bash]: rlocation($1): absolute path without" "drive name" 1>&2;\n' +
    ' fi;\n' +
    ' return 1;\n' +
    ' else\n' +
    ' if [[ -e "${RUNFILES_DIR:-/dev/null}/$1" ]]; then\n' +
    ' if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "INFO[runfiles.bash]: rlocation($1): found under RUNFILES_DIR ($RUNFILES_DIR), return" 1>&2;\n' +
    ' fi;\n' +
    ' echo "${RUNFILES_DIR}/$1";\n' +
    ' else\n' +
    ' if [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then\n' +
    ' if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "INFO[runfiles.bash]: rlocation($1): looking in RUNFILES_MANIFEST_FILE ($RUNFILES_MANIFEST_FILE)" 1>&2;\n' +
    ' fi;\n' +
    ' local -r result=$(grep -m1 "^$1 " "${RUNFILES_MANIFEST_FILE}" | cut -d \' \' -f 2-);\n' +
    ' if [[ -z "$result" ]]; then\n' +
    ' local prefix="$1";\n' +
    ' local prefix_result=;\n' +
    ' local new_prefix=;\n' +
    ' while true; do\n' +
    ' new_prefix="${prefix%/*}";\n' +
    ' [[ "$new_prefix" == "$prefix" ]] && break;\n' +
    ' prefix="$new_prefix";\n' +
    ' prefix_result=$(grep -m1 "^$prefix " "${RUNFILES_MANIFEST_FILE}" | cut -d \' \' -f 2-);\n' +
    ' [[ -z "$prefix_result" ]] && continue;\n' +
    ' local -r candidate="${prefix_result}${1#"${prefix}"}";\n' +
    ' if [[ -e "$candidate" ]]; then\n' +
    ' if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "INFO[runfiles.bash]: rlocation($1): found in manifest as ($candidate) via prefix ($prefix)" 1>&2;\n' +
    ' fi;\n' +
    ' echo "$candidate";\n' +
    ' return 0;\n' +
    ' fi;\n' +
    ' break;\n' +
    ' done;\n' +
    ' if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "INFO[runfiles.bash]: rlocation($1): not found in manifest" 1>&2;\n' +
    ' fi;\n' +
    ' echo "";\n' +
    ' else\n' +
    ' if [[ -e "$result" ]]; then\n' +
    ' if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "INFO[runfiles.bash]: rlocation($1): found in manifest as ($result)" 1>&2;\n' +
    ' fi;\n' +
    ' echo "$result";\n' +
    ' fi;\n' +
    ' fi;\n' +
    ' else\n' +
    ' if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then\n' +
    ' echo "ERROR[runfiles.bash]: cannot look up runfile \\"$1\\" " "(RUNFILES_DIR=\\"${RUNFILES_DIR:-}\\"," "RUNFILES_MANIFEST_FILE=\\"${RUNFILES_MANIFEST_FILE:-}\\")" 1>&2;\n' +
    ' fi;\n' +
    ' return 1;\n' +
    ' fi;\n' +
    ' fi;\n' +
    ' fi;\n' +
    ' fi;\n' +
    ' fi\n' +
    '}',
  OLDPWD: '/',
  JS_BINARY__LOG_ERROR: '1',
  FEDERATION_FILE: '/config/federation.json',
  JS_BINARY__FS_PATCH_ROOTS: '/:/app/hydra-ui/img-bin.sh.runfiles',
  PATH: '/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/hydra-ui/img-bin_node_bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
  JS_BINARY__COMPILATION_MODE: 'fastbuild',
  JS_BINARY__NODE_WRAPPER: '/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/hydra-ui/img-bin_node_bin/node',
  _RLOCATION_ISABS_PATTERN: '^/[^/].*',
  SHLVL: '0',
  JS_BINARY__TARGET: '//hydra-ui:img-bin',
  NODE_CONFIG_DIR: '/config',
  BAZEL_BINDIR: '.',
  JS_BINARY__LOG_PREFIX: 'aspect_rules_js[js_binary]',
  HOME: '/var/www',
  JS_BINARY__NODE_PATCHES: '/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/../aspect_rules_js/js/private/node-patches/register.js',
  JS_BINARY__LOG_FATAL: '1',
  JS_BINARY__TARGET_CPU: 'darwin_arm64',
  PWD: '/',
  JS_BINARY__WORKSPACE: 'com_shadow_cbp',
  RUNFILES_DIR: '/app/hydra-ui/img-bin.sh.runfiles',
  JS_BINARY__BINDIR: 'bazel-out/darwin_arm64-fastbuild-ST-4a519fd6d3e4/bin',
  JS_BINARY__NODE_BINARY: '/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/../nodejs_linux_amd64/bin/nodejs/bin/node',
  JS_BINARY__BUILD_FILE_PATH: 'hydra-ui/BUILD',
  HOSTNAME: 'e795a74203ce',
  RUNFILES: '/app/hydra-ui/img-bin.sh.runfiles',
  JS_BINARY__PATCH_NODE_FS: '1',
  JS_BINARY__NODE_PATCHES_DEPTH: '.'
}

Running the Runfile library in 1.6.X version trigger this error:

/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/node_modules/.aspect_rules_js/@bazel+runfiles@5.7.1/node_modules/@bazel/runfiles/runfiles.js:26
            throw new Error('Every node program run under Bazel must have a $RUNFILES_DIR or $RUNFILES_MANIFEST_FILE environment variable');
            ^

Error: Every node program run under Bazel must have a $RUNFILES_DIR or $RUNFILES_MANIFEST_FILE environment variable
    at new Runfiles (/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/node_modules/.aspect_rules_js/@bazel+runfiles@5.7.1/node_modules/@bazel/runfiles/runfiles.js:26:19)
    at Object.<anonymous> (/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/node_modules/.aspect_rules_js/@bazel+runfiles@5.7.1/node_modules/@bazel/runfiles/index.js:9:20)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/app/hydra-ui/img-bin.sh.runfiles/com_shadow_cbp/node_modules/.aspect_rules_js/@shadow+utils@0.0.0/node_modules/@shadow/utils/src/utils.js:24:12)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)

Version

Bazel 5.3.2
rules_js 1.6.X

How to reproduce

Use the runfile in the E2E js_image project

Any other information?

No response

Fund our work

  • Sponsor our open source work by donating a bug bounty
@supercairos supercairos added the bug Something isn't working label Nov 15, 2022
@gregmagolan gregmagolan assigned thesayyn and unassigned thesayyn Nov 15, 2022
@gregmagolan
Copy link
Member

This looks like a dup of #553 as node_modules/.aspect_rules_js/@bazel+runfiles@5.7.1 is in the callstack

@gregmagolan
Copy link
Member

The fix for this landed in rules_nodejs: bazel-contrib/rules_nodejs@11395ea

Will be available in the next release of @bazel/runfiles

@gregmagolan
Copy link
Member

@bazel/runfiles 5.7.2 is out with the fix https://www.npmjs.com/package/@bazel/runfiles

@gregmagolan
Copy link
Member

@supercairos Can you please update to that version and confirm it solves your problem?

@gregmagolan
Copy link
Member

@devversion Confirmed this fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants