bazelbuild / bazelbuild/rules_docker

go_image always builds for linux/amd64 irrespective of host platform

Open
#2,264 1 comment 0 reactions 0 assignees View on GitHub
Can Close?
Dominant language
Starlark
Stars
1.1k
Forks
689
PR merge metrics
No merged PRs in 30d

Description

# 🐞 bug report

### Affected Rule

The issue is caused by the rule: `rules_docker` and `go_image` (possibly other language-specific rules as well)

### Is this a regression?
Not sure

### Description
When running a `go_image` target from a `darwin/arm64` machine (M1 Pro CPU), the target container image is always built for `linux/amd64`. Below are key snippets



load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")

go_binary(
name = "binary",
srcs = ["main.go"],
goarch = "arm64",
goos = "linux",
)

go_image(
name = "image",
srcs = ["main.go"],
goarch = "arm64",
goos = "linux",
)

## 🔬 Minimal Reproduction
https://github.com/c16a/rules-docker-arm64-reproduction

## 🔥 Exception or Error
There is no build error, but when the image is loaded onto the Docker daemon, it shows the following warning



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

## 🌍 Your Environment

**Operating System:**

  

macOS Ventura 13.4.1

**Output of `bazel version`:**

  

Bazelisk version: development
Build label: 6.3.0
Build target: bazel-out/darwin_arm64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Jul 24 17:26:34 2023 (1690219594)
Build timestamp: 1690219594
Build timestamp as int: 1690219594

**Rules_docker version:**



v0.25.0

**Docker version**



Client:
Cloud integration: v1.0.35
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:51:16 2023
OS/Arch: darwin/arm64
Context: desktop-linux

Server: Docker Desktop 4.21.1 (114176)
Engine:
Version: 24.0.2
API version: 1.43 (minimum version 1.12)
Go version: go1.20.4
Git commit: 659604f
Built: Thu May 25 21:50:59 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.21
GitCommit: 3dce8eb055cbb6872793272b4f20ed16117344f8
runc:
Version: 1.1.7
GitCommit: v1.1.7-0-g860f061
docker-init:
Version: 0.19.0
GitCommit: de40ad0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.