version: '2'

services:

  orderer0:
    container_name: orderer0
    image: hyperledger/fabric-orderer
    environment:
      - ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/localMspConfig
      # enabled TLS
      - ORDERER_GENERAL_TLS_ENABLED=true
      - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/localMspConfig/keystore/ordererSigner.pem
      - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/localMspConfig/signcerts/orderer0Signer.pem
      - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/localMspConfig/cacerts/ordererOrg0.pem]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: orderer
    volumes:
      - ./crypto/orderer:/var/hyperledger/orderer
    ports:
      - 7050:7050

## To enable CouchDB as state database, uncomment the following sections of this file:
## 1) couchdb containers
## 2) peer environment variables CORE_LEDGER_STATE_STATEDATABASE and
##    CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS
## 3) couch container names in "depends_on" section

  couchdb0:
    container_name: couchdb0
    image: hyperledger/fabric-couchdb
#   Uncomment the port mapping if you want to expose the CouchDB service,
#   for example to utilize Fauxton User Interface in dev environments.
    ports:
      - "5984:5984"

  peer0:
    container_name: peer0
    extends:
      file: peer-base/peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0
      - CORE_PEER_ADDRESS=peer0:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0:7051
      - CORE_PEER_LOCALMSPID=Org0MSP
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/signcerts/peer0Signer.pem
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/msp/sampleconfig/keystore/peer0Signer.pem
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/cacerts/peerOrg0.pem
      # - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer0
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984
    volumes:
      - /var/run/:/host/var/run/
      - ./crypto/peer/peer0/localMspConfig:/etc/hyperledger/fabric/msp/sampleconfig
    ports:
      - 7051:7051
      - 7053:7053
    depends_on:
      - orderer0
      - couchdb0

  couchdb1:
    container_name: couchdb1
    image: hyperledger/fabric-couchdb
#   Uncomment the port mapping if you want to expose the CouchDB service,
#   for example to utilize Fauxton User Interface in dev environments.
    ports:
      - "6984:5984"

  peer1:
    container_name: peer1
    extends:
      file: peer-base/peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer1
      - CORE_PEER_ADDRESS=peer1:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0:7051
      - CORE_PEER_LOCALMSPID=Org0MSP
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/signcerts/peer1Signer.pem
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/msp/sampleconfig/keystore/peer1Signer.pem
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/cacerts/peerOrg0.pem
      # - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer1
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb1:5984
    volumes:
      - /var/run/:/host/var/run/
      - ./crypto/peer/peer1/localMspConfig:/etc/hyperledger/fabric/msp/sampleconfig
    ports:
      - 8051:7051
      - 8053:7053
    depends_on:
      - orderer0
      - peer0
      - couchdb1

  couchdb2:
    container_name: couchdb2
    image: hyperledger/fabric-couchdb
#   Uncomment the port mapping if you want to expose the CouchDB service,
#   for example to utilize Fauxton User Interface in dev environments.
    ports:
      - "7984:5984"

  peer2:
    container_name: peer2
    extends:
      file: peer-base/peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer2
      - CORE_PEER_ADDRESS=peer2:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer2:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer2:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/signcerts/peer2Signer.pem
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/msp/sampleconfig/keystore/peer2Signer.pem
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/admincerts/peerOrg1.pem
      #- CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer2
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb2:5984
    volumes:
      - /var/run/:/host/var/run/
      - ./crypto/peer/peer2/localMspConfig:/etc/hyperledger/fabric/msp/sampleconfig
    ports:
      - 9051:7051
      - 9053:7053
    depends_on:
      - orderer0
      - peer0
      - peer1
      - couchdb2

  couchdb3:
    container_name: couchdb3
    image: hyperledger/fabric-couchdb
#   Uncomment the port mapping if you want to expose the CouchDB service,
#   for example to utilize Fauxton User Interface in dev environments.
    ports:
      - "8984:5984"

  peer3:
    container_name: peer3
    extends:
      file: peer-base/peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer3
      - CORE_PEER_ADDRESS=peer3:7051
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer3:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer2:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/signcerts/peer3Signer.pem
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/msp/sampleconfig/keystore/peer3Signer.pem
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/cacerts/peerOrg1.pem
      # - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer3
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb3:5984
    volumes:
      - /var/run/:/host/var/run/
      - ./crypto/peer/peer3/localMspConfig:/etc/hyperledger/fabric/msp/sampleconfig
    ports:
      - 10051:7051
      - 10053:7053
    depends_on:
      - orderer0
      - peer0
      - peer1
      - peer2
      - couchdb3

  cli:
    container_name: cli
    image: hyperledger/fabric-peer
    tty: true
    environment:
      - GOPATH=/opt/gopath
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_NEXT=true
      - CORE_PEER_ID=cli
      - CORE_PEER_ENDORSER_ENABLED=true
      - CORE_PEER_ADDRESS=peer0:7051
      - CORE_PEER_LOCALMSPID=Org0MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig/signcerts/peer0Signer.pem
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig/keystore/peer0Signer.pem
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig/cacerts/peerOrg0.pem
      # - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer0
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig

    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; '
    #command: /bin/bash
    volumes:
      - /var/run/:/host/var/run/
      - ./examples/:/opt/gopath/src/github.com/hyperledger/fabric/examples/
      - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
      - ./crypto:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
      - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
    depends_on:
      - orderer0
      - peer0
      - peer1
      - peer2
      - peer3
