hyperledger-fabric - 如何在 IBM Cloud Functions 操作中使用 Hyperledger Fabric 节点 SDK 包?
问题描述
我正在尝试创建一个使用 Hyperledger Fabric 节点 SDK 包的 IBM Cloud Functions 区块链 node.js 操作,但在操作中需要 fabric-network 包时遇到了问题。
由于它是第 3 方包,看来我需要将操作作为压缩文件上传,但是当我这样做时,我看到:
"error": "Initialization has failed due to: Error: Failed to load gRPC binary module because it was not installed for the current system\nExpected directory: node-v57-linux-x64-glibc\nFound: [node-v57-darwin-x64-unknown]\nThis problem can often be fixed by running \"npm rebuild\" on the current system"
我想创建一个 javascript 操作,如下所示:
'use strict'
const { X509WalletMixin, Gateway } = require('fabric-network')
async function main(params) {
return { message: 'success' }
}
处理这样的 3rd 方包的正确方法是什么?
解决方案
具有本机依赖项的 Node.js 模块需要针对与无服务器运行时相同的平台架构进行编译。如果您node_modules
从本地开发机器捆绑目录,它可能不匹配。
有两种方法可以使用具有本机依赖项的库...
npm install
从平台映像在 Docker 容器内运行。- 使用预安装的库构建自定义运行时映像。
第一种方法最简单,但只能在包含所有源文件和库的 zip 文件小于操作大小限制 (48MB) 时使用。
在运行npm install
时容器内运行
- 运行以下命令将本地目录绑定到运行时容器并运行
npm install
.
docker run -it -v $PWD:/nodejsAction openwhisk/action-nodejs-v10 "npm install"
这将留下一个node_modules
文件夹,其中包含为正确运行时编译的本机依赖项。
- 压缩动作源文件,包括
node_modules
目录。
zip -r action.zip *
- 使用动作存档创建新动作。
ibmcloud wsk action create my-action --kind nodejs:10 action.zip
构建自定义运行时映像
Dockerfile
使用构建期间运行的npm install
命令创建一个。
FROM openwhisk/action-nodejs-v10
RUN npm install fabric-network
- 构建镜像并将其推送到 Docker Hub。
$ docker build -t <USERNAME>/custom-runtime .
$ docker push <USERNAME>/custom-runtime
- 使用自定义运行时映像创建新操作。
ibmcloud wsk action create my-action --docker <USERNAME>/custom-runtime action.zip
确保node_modules
包含在action.zip
不包含相同的库文件。
推荐阅读
- gis - Netlogo GIS - 不支持的文件类型 - shapefile
- graphql - Fastify JWT 与 postgraphile 的使用
- c++ - 带有 C++ 错误的 OCCI:TNS:net 服务名称指定不正确
- python - 在 pyqtgraph 小部件上预设鼠标模式
- c# - 我们可以读取 appsettings 部分中某个键的值并修改转换 web.config 文件中的其他 appsettings 键值吗?
- c++ - 如何在windows上编译linux QT c++
- node.js - Docker/Puppeteer : pthread_create: 资源暂时不可用 (11)
- b-tree - 如何通过查看 B+ 树来获取插入顺序?
- mysql - Mysql,如何禁用特定数据库的连接
- ffmpeg - FFMpeg关于paket pts、dts和duration参数的问题