golang bazel docker 错误:无法启动进程:fork/exec /go/src/my_bin_svc: 功能未实现

huangapple go评论85阅读模式
英文:

golang bazel docker error: could not launch process: fork/exec /go/src/my_bin_svc: function not implemented

问题

我正在尝试为使用Bazel构建的GO二进制文件设置Delve (dlv)调试器。

该二进制文件将在Docker中运行。它单独运行时没有问题。

但是当我尝试设置Delve (dlv)时,我遇到以下错误:

could not launch process: fork/exec /go/src/my_bin_svc: function not implemented

以下是系统和构建工具的描述:

主机系统:Mac OS M1

构建工具:Bazel,构建目标为linux-amd64

运行时环境:Docker(Docker版本20.10.17)

以下是我的Bazel构建命令:

bazelisk build -c dbg --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //...

以下是我针对特定服务的BUILD文件:

load("io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "cmd_lib",
    srcs = ["main.go"],
    importpath = "github.com/xxxxxxxxxx/src/go-grpc-order-svc/cmd",
    visibility = ["//visibility:private"],
    deps = [
        "//pkg/event",
        "//pkg/schema",
        "//proto/order",
        "//src/go-grpc-order-svc/pkg/client",
        "//src/go-grpc-order-svc/pkg/config",
        "//src/go-grpc-order-svc/pkg/db",
        "//src/go-grpc-order-svc/pkg/repository",
        "//src/go-grpc-order-svc/pkg/service",
        "@com_github_tinrab_retry//:retry",
        "@org_golang_google_grpc//:go_default_library",
    ],
)

go_binary(
    name = "cmd",
    embed = [":cmd_lib"],
    goarch = "amd64",
    goos = "linux",
    visibility = ["//visibility:public"],
)

以下是我的Dockerfile:

FROM golang:1.18-bullseye

ENV GOOS="linux"
ENV APP_HOME /go/src
RUN mkdir -p "$APP_HOME"

WORKDIR "$APP_HOME"

EXPOSE 50053
EXPOSE 8080
EXPOSE 4000

RUN GOOS=linux GOARCH=amd64  CGO_ENABLED=0 go install -gcflags="all=-N -l" -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest

ENV GO111MODULE=off

ENTRYPOINT ["/go/bin/linux_amd64/dlv", "--listen=:4000", "--headless=true", "--api-version=2", "--log=true", "exec", "/go/src/my_bin_svc"]

以下是docker-compose中启动我的服务的部分:

my-bin-svc:
    build:
      dockerfile: src/go-grpc-order-svc/Dockerfile.debug
      context: .        
    volumes:
        #- ./bazel-bin/src/go-grpc-order-svc/cmd/cmd_/cmd:/go/src/order_svc
        - ./bazel-out/darwin_arm64-dbg/bin/src/go-grpc-order-svc/cmd/cmd_/cmd:/go/src/my_bin_svc
    ports:
        - "50053:50053"        
    networks:
        - backend          
    links:
        - order-db
    depends_on:
        - order-db  

现在在Bazel中,我有几个包含二进制文件的文件夹:

bazel-out/darwin_arm64-dbg <--- 如果我没有弄错的话,其中包含带有调试符号的二进制文件(我需要与Delve一起使用的内容)。这些二进制文件单独运行时没有问题(不使用Delve),但是当它们被传递给dlv时会出现上述错误。

我还有

bazel-bin <--- 它包含我自己的Linux二进制文件,单独运行时没有问题,但是当它们被传递给dlv时会出现上述错误。

我尝试搜索该特定错误,但目前还没有找到具体的解决方法。

有人遇到过这个错误并且知道是什么原因吗?

谢谢,非常感谢任何帮助。

英文:

I am trying to setup a Delve (dlv) debugger for a GO binary that was built with Bazel.

The binary is to be run within Docker. It runs fine on its own.

But when i try to setup Delve ( dlv ) i get the following error:

could not launch process: fork/exec /go/src/my_bin_svc: function not implemented

Here is the description of the system and build tools:

Host system: Mac OS M1

Build tools: Bazel, building for linux-amd64

Runtime: Docker ( Docker version 20.10.17 )

Here is my bazel build command:

bazelisk build -c dbg --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //...

Here is my BUILD file for my specific service that i am targetting:

load(&quot;@io_bazel_rules_go//go:def.bzl&quot;, &quot;go_binary&quot;, &quot;go_library&quot;)


go_library(
    name = &quot;cmd_lib&quot;,
    srcs = [&quot;main.go&quot;],
    importpath = &quot;github.com/xxxxxxxxxx/src/go-grpc-order-svc/cmd&quot;,
    visibility = [&quot;//visibility:private&quot;],
    deps = [
        &quot;//pkg/event&quot;,
        &quot;//pkg/schema&quot;,
        &quot;//proto/order&quot;,
        &quot;//src/go-grpc-order-svc/pkg/client&quot;,
        &quot;//src/go-grpc-order-svc/pkg/config&quot;,
        &quot;//src/go-grpc-order-svc/pkg/db&quot;,
        &quot;//src/go-grpc-order-svc/pkg/repository&quot;,
        &quot;//src/go-grpc-order-svc/pkg/service&quot;,
        &quot;@com_github_tinrab_retry//:retry&quot;,
        &quot;@org_golang_google_grpc//:go_default_library&quot;,
    ],
)

go_binary(
    name = &quot;cmd&quot;,
    embed = [&quot;:cmd_lib&quot;],
    goarch = &quot;amd64&quot;,
    goos = &quot;linux&quot;,
    visibility = [&quot;//visibility:public&quot;],
)

Here is my Dockerfile:

FROM golang:1.18-bullseye

ENV GOOS=&quot;linux&quot;
ENV APP_HOME /go/src
RUN mkdir -p &quot;$APP_HOME&quot;

WORKDIR &quot;$APP_HOME&quot;


EXPOSE 50053
EXPOSE 8080
EXPOSE 4000

RUN GOOS=linux GOARCH=amd64  CGO_ENABLED=0 go install -gcflags=&quot;all=-N -l&quot; -ldflags &quot;-s -w -extldflags &#39;-static&#39;&quot; github.com/go-delve/delve/cmd/dlv@latest

ENV GO111MODULE=off

ENTRYPOINT [&quot;/go/bin/linux_amd64/dlv&quot;, &quot;--listen=:4000&quot;, &quot;--headless=true&quot;, &quot;--api-version=2&quot;, &quot;--log=true&quot;, &quot;exec&quot;, &quot;/go/src/my_bin_svc&quot;]

Here is the part of docker-compose to start my service:

    my-bin-svc:
        build:
          dockerfile: src/go-grpc-order-svc/Dockerfile.debug
          context: .        
        volumes:
            #- ./bazel-bin/src/go-grpc-order-svc/cmd/cmd_/cmd:/go/src/order_svc
            - ./bazel-out/darwin_arm64-dbg/bin/src/go-grpc-order-svc/cmd/cmd_/cmd:/go/src/my_bin_svc
        ports:
            - &quot;50053:50053&quot;        
        networks:
            - backend          
        links:
            - order-db
        depends_on:
            - order-db  

Now in bazel i have several folders that contain binaries:

bazel-out/darwin_arm64-dbg <--- which if i am not mistaken contains binaries with debugging symbols ( what i need to use with delve ? ). Binaries from here run fine on their own ( without delve ), but give the above error when are given to dlv.

I also have

bazel-bin <--- which contains my linux binaries that run fine on their own, but give the above error when are given to dlv.

I have tried to search for that specific error but so far did not see anything concrete.

Has anyone seen that error and has any idea what this is ?

Thank you, any help is greatly appreciated.

I have tried to use platform specific targets in docker-compose:

platform: linux/amd64

But so far without success.

答案1

得分: 2

这是在ARM架构的amd64容器中进行调试的已知问题,据我所见,唯一的解决方法是使用QEMU模拟或基于linux/arm64的镜像。请参考此问题和原始的dlv仓库报告。第一个链接包含了一些关于如何使其工作的详细信息。

英文:

This is a known issue with debugging in an amd64 container on ARM, and as far as I can see the only workarounds are to either use QEMU emulation or linux/arm64-based images. See also this issue and the original report on the dlv repo. The first link contains some more details on getting it to work

huangapple
  • 本文由 发表于 2023年3月5日 09:00:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75639635.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定