'Fabric Go chaincode install error: Error: error getting chaincode bytes: 'go list'

Im trying to install the golang chaincode inside the peer docker container and Im getting the following error. The installation worked fine with the nodeJs chaincode.

volumes:
  - ./msps/peer4.org1/msp:/etc/hyperledger/fabric/msp
  - ../go-chaincode/dataCC:/opt/gopath/src/github.com/org1/dataCC
  - ./peer4:/opt/gopath/src/github.com/hyperledger/fabric/peer/files
  -  peer4.org1.com:/var/hyperledger/production

Where the go-chaincode/dataCC directory contains the go module of the chaincode.

command

peer lifecycle chaincode package $DATA_CHAINCODETAR_FILE --path $CORE_PEER_CHAINCODE_ID_PATH  --lang golang --label datacc_1

Logs

2020-08-08 02:54:16.263 UTC [bccsp] GetDefault -> DEBU 002 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
2020-08-08 02:54:16.270 UTC [main] InitCmd -> DEBU 003 peer lifecycle chaincode package does not need to init crypto

Error:

error getting chaincode bytes: 'go list' failed: exec: "go": executable file not found in $PATH

docker-container

/opt/gopath/src/github.com/hyperledger/fabric/peer # go list
sh: go: not found


Solution 1:[1]

I tried to replicate the issue and was able to successfully install and instantiate chaincode. Now, this might not be the best way to resolve this, but it certainly worked for me.

  • Go inside your peer/cli container using the command docker exec -it container_name bash(bash/sh according to the container's OS).

  • Install the go binary from here and follow all the installation instructions. Make sure to check go is installed by following the example in the attached link.

  • Run mkdir -p /root/go/src and copy your chaincode folder inside this directory.

  • Install/Package/Instantiate your chaincode.

Make sure to set the environment variable CORE_PEER_MSPCONFIGPATH to the admin's msp directory before installing/packaging the chaincode. The default path is CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/[email protected]/msp.

Try this approach and see if it works for you.

I'll update this answer whenever I find something useful or a better solution.

Solution 2:[2]

Execute below commands and then retry to deploy chaincode:

$go env GOPROXY=https://goproxy.io,direct
$go env GO111MODULE=on

if above command doesn't run properly then execute below commands.

$ export GO111MODULE=on
$ export GOPROXY=https://goproxy.cn

for reference : https://goproxy.cn/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kartik Chauhan
Solution 2 desertnaut