如何将库添加到超级对等体(节点,npm)

时间:2018-01-23 18:14:42

标签: docker npm hyperledger-fabric hyperledger hyperledger-composer

我想知道如何将库添加到hyperledger docker容器中 - 这样你就可以从hyperledeger peer容器中运行node和npm之类的东西了。

使用docker-compose.yml文件有一种简单的方法吗?

当我执行一个通过composer rest服务器从api获取数据的事务时,我收到以下错误:

  

尝试调用业务网络时出错。错误:没有来自任何对等方的有效响应。\ n来自尝试的对等通信的响应是错误:错误:链代码错误(状态:500,消息:ReferenceError:标识符'获取'未定义

(使用javascripts isomorphic-fetch - require('isomorphic-fetch')

当我运行npm test时,此事务从我的命令行开始工作,所以我认为它必须与运行对等图像的docker容器有关,而不是像node和fetch等库。

请参阅下面的示例docker-compose.yaml文件:

 version: '2'
#Detect architecture
services:
  ca.org1.example.com:
    image: hyperledger/fabric-ca:$ARCH-1.0.4
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
      - FABRIC_CA_SERVER_CA_NAME=ca.org1.example.com
#      - FABRIC_CA_SERVER_CA_CERTFILE=/etc/hyperledger/fabric-ca-server-config/org1.example.com-cert.pem
#      - FABRIC_CA_SERVER_CA_KEYFILE=/etc/hyperledger/fabric-ca-server-config/a22daf356b2aab5792ea53e35f66fccef1d7f1aa2b3a2b92dbfbf96a448ea26a_sk

    ports:
      - "7054:7054"
    command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/19ab65abbb04807dad12e4c0a9aaa6649e70868e3abd0217a322d89e47e1a6ae_sk -b admin:adminpw -d'
    volumes:
      - ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
    container_name: ca.org1.example.com

  orderer.example.com:
    container_name: orderer.example.com
    image: hyperledger/fabric-orderer:$ARCH-1.0.4
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/etc/hyperledger/configtx/composer-genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp/orderer/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    ports:
      - 7050:7050
    volumes:
        - ./:/etc/hyperledger/configtx
        - ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/etc/hyperledger/msp/orderer/msp

  peer0.org1.example.com:
    container_name: peer0.org1.example.com
    image: hyperledger/fabric-peer:$ARCH-1.0.4
    environment:
      - CORE_LOGGING_PEER=debug
      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=composer_default
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/msp
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: peer node start --peer-defaultchain=false
    ports:
      - 7051:7051
      - 7053:7053
    volumes:
        - /var/run/:/host/var/run/
        - ./:/etc/hyperledger/configtx
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/peer/msp
        - ./crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/msp/users
    depends_on:
      - orderer.example.com
      - couchdb

  couchdb:
    container_name: couchdb
    image: hyperledger/fabric-couchdb:$ARCH-1.0.4
    ports:
      - 5984:5984
    environment:
      DB_URL: http://localhost:5984/member_db

1 个答案:

答案 0 :(得分:0)

听起来您正在使用我们在1.1预览版中添加的节点链代码功能。您应该能够将依赖项添加到package.json。

e.g。

{
  "name": "mychaincode",
  "version": "1.0.0",
  "description": "My first exciting chaincode implemented in node.js",
  "engines": {
    "node": ">=8.4.0",
    "npm": ">=5.3.0"
  },
  "scripts": {
    "start": "node mychaincode.js"
  },
  "engine-strict": true,
  "engineStrict": true,
  "license": "Apache-2.0",
  "dependencies": {
    "es6-promise": "^4.2.3",
    "fabric-shim": "unastable",
    "isomorphic-fetch": "^2.2.1"
  }
}

有关fabric-chaincode-node的documentation,请参阅编写自己的node.js链代码。请注意,在创建容器时,对等方将执行npm install