After presenting the business network's logical architecture, we will now adopt something similar for our food supply chain. We’ll be using Docker Compose to launch the corresponding Fabric containers, and as a first step we will define the services run in the container using a docker-compose.yml file.
Before we start to define our config files, let's have a look at the project's structure. You should remember that you can get the project code from the Packt website. We have a root folder food-supply-chain/ structured as follows:
There is a base/ folder which contains two base files — peer-base.yaml and docker-compose-base.yaml — which are needed to configure the Docker containers as fabric peers. The chaincode/ folder contains a subfolder foodcontract/ which hosts the Chaincode files.
As we will discover later, the configtxgen tool will generate the output in the channel-artifacts/ folder, as configured in configtx.yaml. Finally, the scripts/ folder contains script.sh and utils.sh, which sets up the Hyperledger network and defines a Chaincode execution scenario, while fscn.sh will be be the script which triggers the execution of the others.
That said, let's start configuring Docker. To make it easy for you, copy the file and base/ directory, along with the docker-compose-cli.yaml file, to your working directory from the Packt source code or fabric-samples/first-network directory (https://github.com/hyperledger/fabric-samples/tree/release-1.2/first-network). Here is an example defining the parameters of the orderer service and a network peer:
# Blockchain by example
version: '2'
services:
orderer.fsc.com:
container_name: orderer.fsc.com
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.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ../crypto-config/ordererOrganizations/fsc.com/orderers/orderer.fsc.com/msp:/var/hyperledger/orderer/msp
- ../crypto-config/ordererOrganizations/fsc.com/orderers/orderer.fsc.com/tls/:/var/hyperledger/orderer/tls
ports:
- 7050:7050
peer0.org1.fsc.com:
container_name: peer0.org1.fsc.com
extends:
file: peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer0.org1.fsc.com
- CORE_PEER_ADDRESS=peer0.org1.fsc.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.fsc.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
volumes:
- /var/run/:/host/var/run/
- ../crypto-config/peerOrganizations/org1.fsc.com/peers/peer0.org1.fsc.com/msp:/etc/hyperledger/fabric/msp
- ../crypto-config/peerOrganizations/org1.fsc.com/peers/peer0.org1.fsc.com/tls:/etc/hyperledger/fabric/tls
ports:
- 7051:7051
- 7053:7053
peer1.org1.fsc.com:
container_name: peer1.org1.fsc.com
extends:
file: peer-base.yaml
service: peer-base
...
You can define the other peers, peer*.org*.fsc.com, in the same way as we did for peer0.org1.fsc.com using their corresponding domain names. For a more complete example, you can have a look at the example listed in the Hyperledger GitHub repository (https://github.com/hyperledger/composer/blob/master/packages/composer-tests-functional/hlfv1/docker-compose.yml). As you may notice, the docker-compose.yml file extends a peer-base.yaml configuration, which can be used as the configuration file for each node:
# Peer network configuration for food Supply Chain
version: '2'
services:
peer-base:
image: hyperledger/fabric-peer
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_fscn
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- CORE_PEER_PROFILE_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
The most important part of the previous file is the line starting with command, which specifies the command that is issued when the container starts.