fabric2.1.0 打包chaincode 报错Error: failed to normalize chaincode path: failed to determine module root

在Ubuntu环境下,使用Fabric-samples的test-networkv2.1.0部署chaincode时遇到权限不足和go命令找不到的问题。通过在.bashrc或.bash_profile中设置sudo环境变量,解决了因sudo导致的$PATH丢失问题,从而成功打包chaincode。解决方案是添加sudo别名以保留环境变量,然后重新执行部署命令。
摘要由CSDN通过智能技术生成

项目场景:

项目场景:Ubunto fabrci-samples/test-network v2.1.0,在打包chaincode的过程中报错不能打包失败。


问题描述:

执行

./network.sh deployCC

会遇到权限不足的问题。
所以执行

sudo ./network.sh deployCC

chaincode 打包失败:

eploying chaincode on channel 'mychannel'

Vendoring Go dependencies ...
/home/lizhe/go/src/fabric-samples/chaincode/fabcar/go /home/lizhe/go/src/fabric-samples/test-network
scripts/deployCC.sh: line 24: go: command not found
/home/lizhe/go/src/fabric-samples/test-network
Finished vendoring Go dependencies
Using organization 1
++ peer lifecycle chaincode package fabcar.tar.gz --path ../chaincode/fabcar/go/ --lang golang --label fabcar_1
++ res=1
++ set +x
Error: failed to normalize chaincode path: failed to determine module root: exec: "go": executable file not found in $PATH
!!!!!!!!!!!!!!! Chaincode packaging on peer0.org1 has failed !!!!!!!!!!!!!!!!

原因分析:

提示scripts/deployCC.sh:line 24: go : command not found,但是确定环境中go已经安装,并且报错的命令为go mod,且确定可以使用。最终发现是应为sudo的原因会重置环境变量导致查找不到可执行的go程序,也就是报错如下

Error: failed to normalize chaincode path: failed to determine module root: exec: "go": executable file not found in $PATH
!!!!!!!!!!!!!!! Chaincode packaging on peer0.org1 has failed !!!!!!!!!!!!!!!!

解决方案:

根据网上解决sudo环境变量的问题
在自己的shell配置文件中如下设置

vim ~/.bashrc 或者 vim ~/.bash_profile 等 添加如下

alias sudo='sudo env PATH=$PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH'
source .bashrc
source .bash_profile

返回test-network目录

sudo ./network.sh deployCC

Vendoring Go dependencies ...
/home/lizhe/go/src/fabric-samples/chaincode/fabcar/go /home/lizhe/go/src/fabric-samples/test-network
/home/lizhe/go/src/fabric-samples/test-network
Finished vendoring Go dependencies
Using organization 1
++ peer lifecycle chaincode package fabcar.tar.gz --path /home/lizhe/go/src/fabric-samples/chaincode/fabcar/go/ --lang golang --label fabcar_1
++ res=0
++ set +x
===================== Chaincode is packaged on peer0.org1 ===================== 

打包成功!

  • 15
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值