HFC:CC 部署成功,而 PEER:"Error building images: ..."

HFC: CC deployment successfull while PEER: "Error building images: ..."

TL;DR;转到 ---- 下面的编辑部分

我在独立的 node.js 应用程序中使用 hfc@0.6.5

membersrvc 和 peer 以 docker-compose 开始,其中:

membersrvc:
  container_name: membersrvc
  image: hyperledger/fabric-membersrvc:latest
  ports:
    - "7054:7054"
  command: membersrvc
vp0:
  container_name: peer
  image: hyperledger/fabric-peer:latest
  ports:
    - "7050:7050"
    - "7051:7051"
    - "7053:7053"
  environment:
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=unix:///var/run/docker.sock
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_ID=vp0
    - CORE_SECURITY_ENABLED=true
    - CORE_PEER_PKI_ECA_PADDR=172.17.0.2:7054
    - CORE_PEER_PKI_TCA_PADDR=172.17.0.2:7054
    - CORE_PEER_PKI_TLSCA_PADDR=172.17.0.2:7054
    - CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=noops
[...]
  links:
    - membersrvc
  command: sh -c "sleep 10; peer node start"

node.js 应用程序成功注册了新用户并尝试使用 enrolledUser.deploy(deployRequest); 方法部署链代码。

作为 deployRequest.chaincodePath 路径的值
'github.com/asset-chaincode/' 是 set.The 目录包含链代码 .go 文件。

deployTx.on('complete', cb) 的回调打印其日志消息:

SUCCESS: Successfully deployed chaincode [chainCodeId:415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58], deploy request={"fcn":"init","args":[],"confidential":true,"metadata":{"type":"Buffer","data":[48,...155,253,0]},"chaincodePath":"github.com/gvlax/chaincodes/asset-chaincode"}, response={"uuid":"415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58","chaincodeID":"415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58"}
chaincodeId=415123c8532fd28393d7a5370193af555e9f2141a4b56e635806e5e1fcce1e58 

但是,当我检查对等控制台的输出时, 我可以看到错误消息

--> full logs here:

        peer       | 15:40:00.416 [dockercontroller] deployImage -> ERRO 47a Error building images: The command '/bin/sh -c go install build-chaincode && cp src/build-chaincode/vendor/github.com/hyperledger/fabric/peer/core.yaml $GOPATH/bin && mv $GOPATH/bin/build-chaincode $GOPATH/bin/23991376d1b935790631a448843fd12a9d60f7ab3f0b8b55f629cf0190077436' returned a non-zero code: 1
    [...]    
        peer       |  ---> Running in 812439684bf7
        peer       | src/build-chaincode/asset-chaincode.go:25:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of:
        peer       |    /opt/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT)
        peer       |    /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOPATH)
        peer       | src/build-chaincode/asset-chaincode.go:26:2: cannot find package "github.com/hyperledger/fabric/core/crypto/primitives" in any of:
        peer       |    /opt/go/src/github.com/hyperledger/fabric/core/crypto/primitives (from $GOROOT)
        peer       |    /opt/gopath/src/github.com/hyperledger/fabric/core/crypto/primitives (from $GOPATH)
        peer       | package build-chaincode
        peer       |    imports github.com/hyperledger/fabric/vendor/github.com/op/go-logging: must be imported as github.com/op/go-logging
    [...]

看起来有些问题与节点上的链代码编译不完全相关。 或者链码被部署到节点上无法解析链码中的相对导入路径的位置....

---- 编辑(几个小时后)

经过多次尝试和实验,我认为我的问题总是一样的:
在使用方法 enrolledUser.deploy(deployRequest) (hfc@0.6.5) 部署到对等点后,无论任何有效的链码(存储在本地目录 $GOPATH/src/gibhub.com/<mychaincode_dir> + 构建中没有错误),结果始终相同目标节点上的错误:

peer       | Step 4 : RUN go install build-chaincode && cp src/build-chaincode/vendor/github.com/hyperledger/fabric/peer/core.yaml $GOPATH/bin && mv $GOPATH/bin/build-chaincode $GOPATH/bin/0881d0fe8f4528e1369bfe917cd207d919a07758cc098e212ca74f6766c636d4
peer       |  ---> Running in b0ca2abbe609
peer       | src/build-chaincode/asset-chaincode.go:25:2: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of:
peer       |    /opt/gopath/src/build-chaincode/vendor/github.com/hyperledger/fabric/core/chaincode/shim (vendor tree)
peer       |    /opt/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT)

同行抱怨的cc的导入是:

import (
    "encoding/base64"
    "errors"
    "fmt"

    "github.com/hyperledger/fabric/core/chaincode/shim"
    [...]  

此外,当我转到对等 CLI 时,可以在那里找到 shim ...

$ docker exec -it peer bash
$ find / -name shim
/opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim
$ echo $GOPATH/
/opt/gopath/

是不是fabric-peer镜像有问题???

当您使用 hfc 部署时,您需要 "vendor" fabric 链代码包 - 请参阅 http://hyperledger-fabric.readthedocs.io/en/v0.6/nodeSDK/node-sdk-indepth/#chaincode-deployment

您也可以查看 https://github.com/IBM-Blockchain/SDK-Demo/tree/master/src/chaincode 以获取使用 SDK 执行此操作的示例