douhui9380 2019-06-11 09:40
浏览 100

与用于Armhf-v7的GitlabCI交叉编译golang应用程序时出现“执行格式错误”

I am trying to use GitlabCI to build a Go binary to ArmV7l.

After a bunch of failed intents, I could successfully compile it with this .gitlab-ci.yml

image: golang
variables:
  PACKAGE_PATH: /go/src/gitlab.com/company/edge_to_bc
  PACKAGE_API_NAME: registry.gitlab.com/company/edge_to_bc
  REGISTRY_URL: https://registry.gitlab.com
  DOCKER_DRIVER: overlay
stages:
  - build
  - publish

# A hack to make Golang-in-Gitlab happy
.anchors:
  - &inject-gopath
      mkdir -p $(dirname ${PACKAGE_PATH})
      && ln -s ${CI_PROJECT_DIR} ${PACKAGE_PATH}
      && cd ${PACKAGE_PATH}


# ==================== TEST ====================
build_binary:
  stage: build
  before_script:
    - *inject-gopath
    - dpkg --add-architecture armhf
    - apt update && apt-get install -y gcc-arm-linux-gnueabihf libltdl-dev:armhf
  script:
    - CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build -v -o ./release/edge_to_bc
  artifacts:
    name: "binary-$CI_PIPELINE_ID"
    paths:
      - release/edge_to_bc
    expire_in: 1 hour

docker-push:
  stage: publish
  before_script:
    - *inject-gopath
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $REGISTRY_URL
  image: docker:stable
  services:
    - docker:dind
  script:
    - docker build -t $PACKAGE_API_NAME:$CI_BUILD_ID  .
    - docker build -t $PACKAGE_API_NAME:latest  .
    - docker push $PACKAGE_API_NAME:$CI_BUILD_ID
    - docker push $PACKAGE_API_NAME:latest
  dependencies:
    - build_binary

Here is my Dockerfile.

FROM alpine:3.7

RUN apk --no-cache add ca-certificates libtool

WORKDIR /sunclient/

COPY ./release/edge_to_bc /sunclient/
EXPOSE 5555

CMD [ "./edge_to_bc" ]

When I run it on my ARM board, I get:

[root@artik system]# docker run -it  registry.gitlab.com/company/edge_to_bc:latest bash
standard_init_linux.go:207: exec user process caused "exec format error"

When I want to debug it, with bash:

[root@artik system]# docker run registry.gitlab.com/company/edge_to_bc:latest
standard_init_linux.go:207: exec user process caused "no such file or directory"

What should I do ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog