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

collect2: fatal error: cannot find 'ld' when compiling peer binary from inside Dockerfile #4

Open
maciejjedrzejczyk opened this issue Sep 19, 2021 · 0 comments

Comments

@maciejjedrzejczyk
Copy link

maciejjedrzejczyk commented Sep 19, 2021

Bug description:

I managed to successfully compile all containers and binaries outside of Dockerfile context apart from peer. Both Dockerfiles for peer and fabric-tools fail at this stage with the following error (example from invocation of make tools-docker):

Building Docker image hyperledger/fabric-tools
docker build --force-rm  -f images/tools/Dockerfile \
        --build-arg GO_VER=1.16.7 \
        --build-arg ALPINE_VER=3.14 \
        --build-arg GO_TAGS= \
        -t hyperledger/fabric-tools ./
Sending build context to Docker daemon  45.14MB
Step 1/15 : ARG GO_VER
Step 2/15 : ARG ALPINE_VER
Step 3/15 : FROM golang:${GO_VER}-alpine${ALPINE_VER} as golang
 ---> 37359516ee13
Step 4/15 : RUN apk add --no-cache      bash    gcc     git     make    musl-dev;
 ---> Using cache
 ---> 49aa03a2dcc8
Step 5/15 : ADD . $GOPATH/src/github.com/hyperledger/fabric
 ---> Using cache
 ---> 9b400a79a464
Step 6/15 : WORKDIR $GOPATH/src/github.com/hyperledger/fabric
 ---> Using cache
 ---> e5fcadfdaa23
Step 7/15 : FROM golang as tools
 ---> e5fcadfdaa23
Step 8/15 : ARG GO_TAGS
 ---> Using cache
 ---> 63a6837855f9
Step 9/15 : RUN make peer configtxgen configtxlator cryptogen discover osnadmin idemixgen GO_TAGS=${GO_TAGS}
 ---> Running in df6c75600288
Building build/bin/peer
GOBIN=/go/src/github.com/hyperledger/fabric/build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=2.3.3 -X github.com/hyperledger/fabric/common/metadata.CommitSHA=9955302 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger" github.com/hyperledger/fabric/cmd/peer
# github.com/hyperledger/fabric/cmd/peer
/usr/local/go/pkg/tool/linux_arm64/link: running gcc failed: exit status 1                                                               
collect2: fatal error: cannot find 'ld'                                                                                                  
compilation terminated.                                                                                                                  
                                                                                                                                         
make: *** [Makefile:211: build/bin/peer] Error 2                                                                                         
Removing intermediate container df6c75600288                                                                                             
The command '/bin/sh -c make peer configtxgen configtxlator cryptogen discover osnadmin idemixgen GO_TAGS=${GO_TAGS}' returned a non-zero code: 2
make: *** [Makefile:229: build/images/tools/.dummy-arm64-2.3.3-snapshot-99553020d] Error 2

Reproduction of the issue:

OS and Version: DietPi 7.5.2
Platform: Raspberry Pi 4
golang version: v1.15.9

I tested this issue against v2.1.0, v2.2.0 and v.2.3.0 by executing make peer-docker or make tools-docker from go/src/github.com/hyperledger/fabric folder, with same effect. The ld binary is well present in alpine container used for this purpose by Dockerfile in /home/mj/go/src/github.com/hyperledger/fabric/images/peer folder and can be invoked from any location within the transitive container created by these respective Dockerfiles in /peer and /tools folders. All other binaries compile without any problems.

Since peer binary and all other binaries can be compiled on the host, there is no issue with an underlying development environment. This is also not a version-dependent issue since I tried to execute the same command on all most recent branches, with same effect. I also tried using a specific version of golang alpine container downloaded during the execution of make peer-docker or make tools-docker. I tried:

  • 1.16.7-alpine3.14
  • 1.16.7-alpine3.13
  • 1.15.7-alpine3.12
  • 1.14.4-alpine3.12
  • 1.14.1-alpine3.11

However, with same effects.

Known workarounds:

  • Workaround 1

The workaround for this is to compile peer binary outside of the context of /image/peer/Dockerfile or /image/tools/Dockerfile, add it to transitive containers with ADD commands and comment out make peer command in respective Dockerfiles. I successfully compile peer binary on DietPi based on Debian Buster, installed on Raspberry Pi 4 with go v1.15.9.

  • Workaround 2

Replace alpine docker with debian buster for both tools and peer. Example


ARG GO_VER
#ARG ALPINE_VER
#FROM golang:${GO_VER}-alpine${ALPINE_VER} as golang
FROM golang:${GO_VER}-buster as golang

RUN apt-get update \
    && apt-get install -y curl \
    git \
    gcc \
    make \
    musl-dev \
    bash \
    tar \
    binutils \
    gnupg;

ADD . $GOPATH/src/github.com/hyperledger/fabric
WORKDIR $GOPATH/src/github.com/hyperledger/fabric

FROM golang as tools
ARG GO_TAGS
RUN make peer configtxgen configtxlator cryptogen discover osnadmin idemixgen GO_TAGS=${GO_TAGS}

FROM golang:${GO_VER}-buster

RUN apt-get update \
    && apt-get install -y jq \
    tzdata \
    git \
    bash;

ENV FABRIC_CFG_PATH /etc/hyperledger/fabric
VOLUME /etc/hyperledger/fabric
COPY --from=tools /go/src/github.com/hyperledger/fabric/build/bin /usr/local/bin
COPY --from=tools /go/src/github.com/hyperledger/fabric/sampleconfig ${FABRIC_CFG_PATH}


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

No branches or pull requests

1 participant