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

nodejs_image build issue #3357

Closed
trammel-may opened this issue Mar 7, 2022 · 5 comments
Closed

nodejs_image build issue #3357

trammel-may opened this issue Mar 7, 2022 · 5 comments
Assignees
Labels

Comments

@trammel-may
Copy link

trammel-may commented Mar 7, 2022

🐞 bug report

Affected Rule

The issue is caused by the rule:

nodejs_image

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

This worked in previous versions

http_archive(
    name = "build_bazel_rules_nodejs",
    sha256 = "f0f76a06fd6c10e8fb9a6cb9389fa7d5816dbecd9b1685063f89fb20dc6822f3",
    urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.5.1/rules_nodejs-4.5.1.tar.gz"],
)

http_archive(
    name = "io_bazel_rules_docker",
    sha256 = "85ffff62a4c22a74dbd98d05da6cf40f497344b3dbf1e1ab0a37ab2a1a6ca014",
    strip_prefix = "rules_docker-0.22.0",
    urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.22.0/rules_docker-v0.22.0.tar.gz"],
)

Description

This configuration will result in a build where the image layer contains the incorrect node_tool_path. This results in an error (see below) when attempting to run the nodejs_image.

The expected node_tool_path

readonly node_tool_path="nodejs_linux_amd64/bin/nodejs/bin/node"

The actual node_tool_path

readonly node_tool_path="nodejs_darwin_amd64/bin/nodejs/bin/node"

🔬 Minimal Reproduction

A minimal reproduction has been attached. Please unzip the attached zipfile, cd into the project directory and run make.

🔥 Exception or Error


WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
/app/packages/example/example: line 190: /app/packages/example/example.runfiles/nodejs_darwin_amd64/bin/nodejs/bin/node: cannot execute binary file: Exec format error
make: *** [image] Error 126

🌍 Your Environment

Operating System:

  
macOS Monterey
Version 12.1
Mac mini (M1, 2020)
  

Output of bazel version:

  
Bazelisk version: v1.9.0
Build label: 4.2.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Aug 18 12:54:03 2021 (1629291243)
Build timestamp: 1629291243
Build timestamp as int: 1629291243
  

Rules_nodejs version:

(Please check that you have matching versions between WORKSPACE file and @bazel/* npm packages.)

Anything else relevant?
nodejs_image_issue.zip

@thesayyn thesayyn self-assigned this Mar 21, 2022
@thesayyn
Copy link
Collaborator

thesayyn commented Mar 21, 2022

I can confirm that images that are built from non-linux/amd64 hosts are likely to be broken.

Workaround is to have a nodejs_binary with the right toolchain attribute set then passed to nodejs_image.

example for linux/amd64 images

nodejs_binary(
  name = "example",
  toolchain = "@nodejs_linux_amd64//:node_toolchain"
  ...
)

nodejs_image(
  name = "nodejs_image",
  binary = ":example",
  node_repository_name = "nodejs_linux_amd64"
)

@trammel-may
Copy link
Author

Thanks, I will try this out and get back to you, but looks like a non-intrusive workaround.

@trammel-may
Copy link
Author

@thesayyn sorry for the late response, but I wanted to confirm for you that workaround does in fact work. Thanks!

@thesayyn
Copy link
Collaborator

thesayyn commented Mar 29, 2022

fixed by #3373 in version 5.3.1

@trammel-may
Copy link
Author

@thesayyn I am currently still using the workaround. With the fix, can I now remove the toolchain and node repository name from the binary and image rules?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants