rules_docker icon indicating copy to clipboard operation
rules_docker copied to clipboard

Building and testing rules_docker on Apple Silicon

Open linzhp opened this issue 3 years ago • 9 comments

🚀 feature request

Relevant Rules

Description

Currently, the Go targets in rules_docker cannot build on Apple Silicon machines:

bazel build @io_bazel_rules_docker//container/go/...                        
DEBUG: /private/var/tmp/_bazel_zplin/d6323f9e3146540840037c805ccd73ff/external/bazel_toolchains/rules/rbe_repo/version_check.bzl:68:14: 
Current running Bazel is ahead of bazel-toolchains repo. Please update your pin to bazel-toolchains repo in your WORKSPACE file.
DEBUG: /private/var/tmp/_bazel_zplin/d6323f9e3146540840037c805ccd73ff/external/bazel_toolchains/rules/rbe_repo/checked_in.bzl:125:14: buildkite_config not using checked in configs; Bazel version 5.0.0 was picked/selected but no checked in config was found in map {"0.20.0": ["8.0.0"], "0.21.0": ["8.0.0"], "0.22.0": ["8.0.0", "9.0.0"], "0.23.0": ["8.0.0", "9.0.0"], "0.23.1": ["8.0.0", "9.0.0"], "0.23.2": ["9.0.0"], "0.24.0": ["9.0.0"], "0.24.1": ["9.0.0"], "0.25.0": ["9.0.0"], "0.25.1": ["9.0.0"], "0.25.2": ["9.0.0"], "0.26.0": ["9.0.0"], "0.26.1": ["9.0.0"], "0.27.0": ["9.0.0"], "0.27.1": ["9.0.0"], "0.28.0": ["9.0.0"], "0.28.1": ["9.0.0"], "0.29.0": ["9.0.0"], "0.29.1": ["9.0.0", "10.0.0"], "1.0.0": ["9.0.0", "10.0.0"], "1.0.1": ["10.0.0"], "1.1.0": ["10.0.0"], "1.2.0": ["10.0.0"], "1.2.1": ["10.0.0"], "2.0.0": ["10.0.0"], "2.1.0": ["10.0.0"], "2.1.1": ["10.0.0", "11.0.0"], "2.2.0": ["11.0.0"], "3.0.0": ["11.0.0"], "3.1.0": ["11.0.0"], "3.2.0": ["11.0.0"], "3.3.0": ["11.0.0"], "3.3.1": ["11.0.0"], "3.4.1": ["11.0.0"], "3.5.0": ["11.0.0"], "3.5.1": ["11.0.0"], "3.6.0": ["11.0.0"], "3.7.0": ["11.0.0"], "3.7.1": ["11.0.0"], "3.7.2": ["11.0.0"], "4.0.0": ["11.0.0"]}
ERROR: /Users/zplin/go/src/github.com/bazelbuild/rules_docker/container/go/cmd/digester/BUILD:31:10: While resolving toolchains for target //container/go/cmd/digester:digester: no matching toolchains found for types @io_bazel_rules_go//go:toolchain
ERROR: Analysis of target '//container/go/cmd/digester:digester' failed; build aborted: 
INFO: Elapsed time: 0.152s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (13 packages loaded, 0 targets configured)

As a result, end-to-end tests cannot run on Apple Silicon either:

testing/e2e.sh test_container_pull_with_auth
"docker rmi" requires at least 1 argument.
See 'docker rmi --help'.

Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images
9639f55a2c962719389fc290439ec41b9f583d7322397f20b1485ed47e5f2b86
Error: No such image: bazel/image:image
ERROR: /private/var/tmp/_bazel_zplin/aa79edc14e712d12745728305b89bbcc/external/io_bazel_rules_docker/container/go/cmd/join_layers/BUILD:19:10: While resolving toolchains for target @io_bazel_rules_docker//container/go/cmd/join_layers:join_layers: no matching toolchains found for types @io_bazel_rules_go//go:toolchain
ERROR: Analysis of target '@io_bazel_rules_docker//tests/container:push_test' failed; build aborted: 
INFO: Elapsed time: 2.059s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (12 packages loaded, 669 targets configured)
FAILED: Build did NOT complete successfully (12 packages loaded, 669 targets configured)

Describe the solution you'd like

Probably involving upgrading rules_go and some bug fixing in testing/e2e.sh.

Describe alternatives you've considered

Have you considered any alternative solutions or workarounds?

linzhp avatar Mar 01 '22 15:03 linzhp

I've worked around by installing the latest gazelle dependencies in my WORKSPACE

chajath avatar Jul 18 '22 16:07 chajath

I came across this issue as well and fixed it as described in this thread.

gillesmag avatar Jul 24 '22 21:07 gillesmag

I just encountered this (on Mac M1 as well). From what I can tell, this looks like a regression in rules_go v0.34.0. I get the error in that version, but I also tried the 5 previous releases and those work fine. I've filed https://github.com/bazelbuild/rules_go/issues/3269 in that repo to track my particular issue, though I'm not sure it has the same root cause.

stabai avatar Aug 12 '22 05:08 stabai

I've worked around by installing the latest gazelle dependencies in my WORKSPACE

Yes, It works.

zhangw avatar Sep 17 '22 04:09 zhangw

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!

github-actions[bot] avatar Mar 17 '23 02:03 github-actions[bot]

This issue is still present

avarun42 avatar Mar 17 '23 18:03 avarun42

I can confirm that the issue still present.


http_archive(
    name = "io_bazel_rules_docker",
    sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
    urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.25.0/rules_docker-v0.25.0.tar.gz"],
)

load("@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories")

container_repositories()

load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")

container_deps()

load("@io_bazel_rules_docker//go:image.bzl", _go_image_repos = "repositories")

_go_image_repos()

icaromag avatar May 10 '23 22:05 icaromag

To be able to build, I needed to add the following to my .bazelrc:

build --@io_bazel_rules_docker//transitions:enable=false

After that, you can build but it. If this error pops up:

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested...

It indicates that the binary you're trying to run was built for a different architecture than the one you're currently using. Specifically, the binary was built for amd64 (aka x86_64), but your system is arm64.

So, the solution is to use this for building and running:

bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 //:bananas bazel run --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 //:bananas

Or just edit your .bazelrc ✨

icaromag avatar May 10 '23 23:05 icaromag