Skip to content

Instantly share code, notes, and snippets.

@rtang03
Created March 26, 2020 06:46
Show Gist options
  • Save rtang03/77927fc2ad4f60613315cf3e0df55139 to your computer and use it in GitHub Desktop.
Save rtang03/77927fc2ad4f60613315cf3e0df55139 to your computer and use it in GitHub Desktop.
Experimental Fabric V2 network
#!/usr/bin/env bash
# $1 - docker compose files
# $2 - orderer code ("org0")
# $3 - first org ("org1")
# $4 - list of remaining orgs ("org2 org3")
# $5 - number of orgs (2org / 3org)
. ./scripts/setup.sh
docker-compose $1 up -d
printMessage "docker-compose up" $?
sleep 5
docker exec cli sh -c "cp -f /config/configtx.${5}.yaml /config/configtx.yaml"
sleep 1
printf "\n###########################"
printf "\n# CREATE CRYPTO MATERIALS #"
printf "\n###########################\n"
ORGLIST="$3 $4"
docker exec tls-ca-${2} sh -c "/setup/enroll-tls.sh ${2} \"$ORGLIST\""
printMessage "enroll-tls.sh" $?
docker exec rca-${2} sh -c "/setup/enroll-orderer.sh ${2}"
printMessage "enroll-orderer.sh" $?
for ORG in $ORGLIST
do
docker exec rca-${ORG} sh -c "/setup/enroll-org.sh $ORG"
printMessage "enroll-org.sh $ORG" $?
done
docker-compose $1 up -d
sleep 5
# Params of the orderer
getConfig ${2}
ORDERER_NAME=$NAME
ORDERER_PEER=$PEER
ORDERER_DOMAIN=$DOMAIN
ORDERER_PORT=$PORT
docker exec cli sh -c "/setup/copy-certs.sh ${CRYPTO} ${NAME} ${DOMAIN} ${PEER}"
for ORG in $ORGLIST
do
getConfig $ORG
docker exec cli sh -c "/setup/copy-certs.sh ${CRYPTO} ${NAME} ${DOMAIN} ${PEER}"
done
printf "\n##################################"
printf "\n# CREATE GENESIS BLOCK/CONFIG.TX #"
printf "\n##################################\n"
docker exec -w /config -e FABRIC_CFG_PATH=/config cli \
sh -c "configtxgen -profile OrgsOrdererGenesis -outputBlock genesis.block -channelID ordererchannel"
printMessage "Create genesis block" $?
docker exec -w /config -e FABRIC_CFG_PATH=/config cli \
sh -c "configtxgen -profile OrgsChannel -outputCreateChannelTx channel.tx -channelID loanapp"
printMessage "Create channel.tx" $?
docker exec -w /config cli sh -c "mv genesis.block ${CRYPTO}/${ORDERER_NAME}MSP/${ORDERER_PEER}.${ORDERER_DOMAIN}"
# Params of the first org
getConfig $3
FIRST_NAME=$NAME
FIRST_PEER=$PEER
FIRST_DOMAIN=$DOMAIN
FIRST_GATEWAY=$GATEWAY
FIRST_PORT=$PORT
docker exec -w /config cli sh -c "mv channel.tx ${CRYPTO}/${NAME}MSP/${PEER}.${DOMAIN}/assets"
docker-compose $1 up -d
sleep 5
docker exec cli sh -c "mkdir -p ${CRYPTO}/${NAME}MSP/admin/msp/admincerts"
docker exec cli sh -c "cp ${CRYPTO}/${NAME}MSP/${PEER}.${DOMAIN}/msp/admincerts/${DOMAIN}-admin-cert.pem /var/artifacts/crypto-config/${NAME}MSP/admin/msp/admincerts"
printf "\n##################"
printf "\n# CREATE CHANNEL #"
printf "\n##################\n"
docker exec \
-e CORE_PEER_ADDRESS=${PEER}-${3}:${PORT} \
-e CORE_PEER_LOCALMSPID=${NAME}MSP \
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/${NAME}MSP/admin/msp \
cli peer channel create -c loanapp -f /var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/assets/channel.tx -o ${ORDERER_PEER}-${2}:${ORDERER_PORT} \
--outputBlock /var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/assets/loanapp.block \
--tls --cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
printMessage "Create channel" $?
printf "\n###########################"
printf "\n# JOIN CHANNEL - $3"
printf "\n###########################\n"
docker exec \
-e CORE_PEER_ADDRESS=${PEER}-${3}:${PORT} \
-e CORE_PEER_LOCALMSPID=${NAME}MSP \
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/${NAME}MSP/admin/msp \
cli peer channel join -b /var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/assets/loanapp.block
printMessage "Join channel" $?
docker exec cli sh -c "peer channel getinfo -c loanapp"
for ORG in $4
do
getConfig $ORG
printf "\n###########################"
printf "\n# JOIN CHANNEL - $NAME"
printf "\n###########################\n"
docker exec cli sh -c "cp /var/artifacts/crypto-config/${FIRST_NAME}MSP/${FIRST_PEER}.${FIRST_DOMAIN}/assets/loanapp.block /var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/assets"
docker exec cli sh -c "mkdir -p ${CRYPTO}/${NAME}MSP/admin/msp/admincerts"
docker exec cli sh -c "cp ${CRYPTO}/${NAME}MSP/${PEER}.${DOMAIN}/msp/admincerts/${DOMAIN}-admin-cert.pem /var/artifacts/crypto-config/${NAME}MSP/admin/msp/admincerts"
docker exec -w /config \
-e CORE_PEER_ADDRESS=${PEER}-${ORG}:${PORT} \
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/${NAME}MSP/admin/msp \
-e CORE_PEER_LOCALMSPID=${NAME}MSP \
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
cli peer channel fetch newest /config/loanapp_newest.block \
-o ${ORDERER_PEER}-${2}:${ORDERER_PORT} -c loanapp --tls \
--cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
printMessage "Fetch block" $?
docker exec -w /config \
-e CORE_PEER_ADDRESS=${PEER}-${ORG}:${PORT} \
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/${NAME}MSP/admin/msp \
-e CORE_PEER_LOCALMSPID=${NAME}MSP \
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
cli sh -c "peer channel join -b /config/loanapp_newest.block"
printMessage "Join channel" $?
docker exec -w /config cli sh -c "rm loanapp_newest.block"
docker exec \
-e CORE_PEER_ADDRESS=${PEER}-${ORG}:${PORT} \
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/${NAME}MSP/admin/msp \
-e CORE_PEER_LOCALMSPID=${NAME}MSP \
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
cli sh -c "peer channel getinfo -c loanapp"
done
cd $CHAINCODE && yarn build
printMessage "Build chaincode" $?
PEER0_ORG1="docker exec
-e CORE_PEER_ADDRESS=${FIRST_PEER}-${3}:${FIRST_PORT}
-e CORE_PEER_LOCALMSPID=${FIRST_NAME}MSP
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/${FIRST_NAME}MSP/${PEER}.${FIRST_DOMAIN}/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/${FIRST_NAME}MSP/admin/msp
cli peer "
# --tls=true
# -o ${ORDERER_PEER}-${2}:${ORDERER_PORT}
# --cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem "
printf "\n######################"
printf "\n# PACKAGE CC ON ORG1 #"
printf "\n######################\n"
echo "executing => $PEER0_ORG1 lifecycle chaincode package eventstore.tar.gz"
${PEER0_ORG1} lifecycle chaincode package eventstore.tar.gz \
--tls \
-o ${ORDERER_PEER}-${2}:${ORDERER_PORT} \
--cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
--path /opt/gopath/src/github.com/hyperledger/fabric/chaincode \
--lang node \
--label eventstorev1
printMessage "Package chaincode eventstorev1.tar.gz" $?
#peer --tls --cafile=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem --orderer=orderer0-org0:7050 lifecycle chaincode package
# eventstore.tar.gz --path /opt/gopath/src/github.com/hyperledger/fabric/chaincode --lang node --label eventstorev1
for ORG in $ORGLIST
do
getConfig $ORG
printf "\n#####################"
printf "\n# INSTALL CHAINCODE #"
printf "\n#####################\n"
echo "Installing smart contract on ${PEER}-${ORG}"
PEER_ORG="docker exec
-e CORE_PEER_ADDRESS=${PEER}-${ORG}:${PORT}
-e CORE_PEER_LOCALMSPID=${NAME}MSP
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/${NAME}MSP/admin/msp
cli peer --tls=true
--cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
-o ${ORDERER_PEER}-${2}:${ORDERER_PORT} "
echo "executing => $PEER_ORG lifecycle chaincode install eventstore.tar.gz"
${PEER_ORG} lifecycle chaincode install eventstore.tar.gz
printMessage "Install chaincode: eventstore for $ORG" $?
done
for ORG in $ORGLIST
do
getConfig $ORG
PEER_ORG="docker exec
-e CORE_PEER_ADDRESS=${PEER}-${ORG}:${PORT}
-e CORE_PEER_LOCALMSPID=${NAME}MSP
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/${NAME}MSP/${PEER}.${DOMAIN}/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/${NAME}MSP/admin/msp
cli peer --tls=true
--cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
-o ${ORDERER_PEER}-${2}:${ORDERER_PORT} "
echo "Determining package ID for smart contract on peer0.org1.example.com"
REGEX='Package ID: (.*), Label: eventstorev1'
if [[ `${PEER_ORG} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
PACKAGE_ID=${BASH_REMATCH[1]}
else
echo "Could not find package ID for eventstorev1 chaincode on peer0-org1"
exit 1
fi
printMessage "query packageId ${PACKAGE_ID}" $?
printf "\n#####################"
printf "\n# APPROVE CHAINCODE #"
printf "\n#####################\n"
echo "executing => $PEER_ORG lifecycle approveformyorg ..."
# additional config may require for approveformyorg
# --signature-policy "OR('Org1MSP.member','Org2MSP.member')" \
# --channel-config-policy "OR('Org1MSP.member','Org2MSP.member')" \
${PEER_ORG} lifecycle chaincode approveformyorg \
--tls \
-o ${ORDERER_PEER}-${2}:${ORDERER_PORT} \
--cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
--package-id ${PACKAGE_ID} \
--channelID loanapp \
--init-required \
--name evenstore \
--version 1.0 \
--sequence 1 \
--waitForEvent
printMessage "approveformyorg for ${ORG}" $?
done
echo "Checkcommitreadiness"
docker exec \
-e CORE_PEER_ADDRESS=peer0-org1:7051 \
-e CORE_PEER_LOCALMSPID=Org1MSP \
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/Org1MSP/admin/msp \
cli peer lifecycle chaincode checkcommitreadiness --tls \
--cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
-o orderer0-org0:7050 \
--channelID loanapp \
--name evenstore \
--init-required \
--signature-policy "AND('Org1MSP.member','Org2MSP.member')" \
--version 1.0 \
--sequence 1
printMessage "checkcommitreadiness" $?
printf "\n####################"
printf "\n# COMMIT CHAINCODE #"
printf "\n####################\n"
echo "executing => $PEER0_ORG1 lifecycle chaincode commit ..."
docker exec \
-e CORE_PEER_ADDRESS=peer0-org1:7051 \
-e CORE_PEER_LOCALMSPID=Org1MSP \
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/Org1MSP/admin/msp \
cli peer lifecycle chaincode commit \
--tls \
-o "${ORDERER_PEER}-${2}:${ORDERER_PORT}" \
--cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
--channelID loanapp \
--name evenstore \
--init-required \
--version 1.0 \
--sequence 1 \
--waitForEvent \
--peerAddresses peer0-org1:7051 \
--peerAddresses peer0-org2:7251 \
--tlsRootCertFiles /var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
--tlsRootCertFiles /var/artifacts/crypto-config/Org2MSP/peer0.org2.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
printMessage "commit chaincode" $?
sleep 5
printf "\n####################"
printf "\n# Init CHAINCODE #"
printf "\n####################\n"
echo "executing => $PEER0_ORG1 chaincode invoke"
docker exec \
-e CORE_PEER_ADDRESS=peer0-org1:7051 \
-e CORE_PEER_LOCALMSPID=Org1MSP \
-e CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
-e CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/Org1MSP/admin/msp \
cli peer chaincode invoke \
--tls true \
-o orderer0-org0:7050 \
--cafile /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
--isInit \
-C loanapp \
-n eventstore \
-c '{"Args":["Init"]}' \
--waitForEvent \
--waitForEventTimeout 300s \
--peerAddresses peer0-org1:7051 \
--tlsRootCertFiles /var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem \
--peerAddresses peer0-org2:7251 \
--tlsRootCertFiles /var/artifacts/crypto-config/Org2MSP/peer0.org2.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
printMessage "init chaincode" $?
docker exec cli sh -c "rm -f /config/configtx.yaml"
sleep 1
printf "${GREEN}### BOOTSTRAP DONE ###${NC}\n\n"
version: '2'
networks:
openplatform:
services:
tls-ca-org0:
extends:
file: nodebase.yaml
service: ca
container_name: tls-ca-org0
environment:
- HYPERLEDGER_VOL=/var/artifacts
- FABRIC_CA_SERVER_HOME=/var/artifacts/crypto-config/Org0MSP/tls/server
- FABRIC_CA_SERVER_CSR_CN=tls-ca-org0
- FABRIC_CA_SERVER_CA_NAME=tls-ca-org0
ports:
- 5052:5052
command: sh -c 'fabric-ca-server start -d -b tls-ca-admin:tls-ca-adminPW --cfg.affiliations.allowremove --cfg.identities.allowremove --port 5052'
volumes:
- $SCRIPTS:/setup
- $ARTIFACTS:/var/artifacts
rca-org0:
extends:
file: nodebase.yaml
service: ca
container_name: rca-org0
environment:
- HYPERLEDGER_VOL=/var/artifacts
- FABRIC_CA_SERVER_HOME=/var/artifacts/crypto-config/Org0MSP/ca/server
- FABRIC_CA_SERVER_CSR_CN=rca-org0
- FABRIC_CA_SERVER_CA_NAME=rca-org0
ports:
- 5053:5053
command: sh -c 'fabric-ca-server start -d -b rca-org0-admin:rca-org0-adminPW --cfg.affiliations.allowremove --cfg.identities.allowremove --port 5053'
volumes:
- $SCRIPTS:/setup
- $ARTIFACTS:/var/artifacts
orderer0-org0:
extends:
file: nodebase.yaml
service: orderer
container_name: orderer0-org0
environment:
- ORDERER_HOST=orderer0-org0
- ORDERER_HOME=/var/artifacts/orderer
- ORDERER_GENERAL_LOCALMSPID=Org0MSP
- ORDERER_GENERAL_LOCALMSPDIR=/var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/msp
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/signcerts/cert.pem
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/keystore/key.pem
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem]
- ORDERER_GENERAL_GENESISFILE=/var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/genesis.block
- ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/signcerts/cert.pem
- ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/keystore/key.pem
- ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem]
- ORDERER_GENERAL_LISTENPORT=7050
volumes:
- $ARTIFACTS:/var/artifacts
ports:
- 7050:7050
cli:
extends:
file: nodebase.yaml
service: cli
container_name: cli
environment:
- HYPERLEDGER_VOL=/var/artifacts
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0-org1:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
- CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org1
command: sh
volumes:
- $ARTIFACTS:/var/artifacts
- $SCRIPTS:/setup
- $CONFIG:/config
- $CHAINCODE:/opt/gopath/src/github.com/hyperledger/fabric/chaincode
# ORG1
rca-org1:
extends:
file: nodebase.yaml
service: ca
container_name: rca-org1
restart: always
environment:
- HYPERLEDGER_VOL=/var/artifacts
- FABRIC_CA_SERVER_HOME=/var/artifacts/crypto-config/Org1MSP/ca/server
- FABRIC_CA_SERVER_CSR_CN=rca-org1
- FABRIC_CA_SERVER_CA_NAME=rca-org1
ports:
- 5054:5054
command: sh -c 'fabric-ca-server start -d -b rca-org1-admin:rca-org1-adminPW --cfg.affiliations.allowremove --cfg.identities.allowremove --port 5054'
volumes:
- $SCRIPTS:/setup
- $ARTIFACTS:/var/artifacts
peer0-org1:
extends:
file: nodebase.yaml
service: peer
container_name: peer0-org1
environment:
- CORE_PEER_ID=peer0-org1
- CORE_PEER_ADDRESS=peer0-org1:7051
- CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/msp
- CORE_PEER_TLS_CERT_FILE=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/signcerts/cert.pem
- CORE_PEER_TLS_KEY_FILE=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/keystore/key.pem
- CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/Org1MSP/peer0.org1.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
# - CORE_PEER_GOSSIP_BOOTSTRAP=peer1-org1:7151
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0-org1:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0-org1:7051
- CORE_PEER_CHAINCODEADDRESS=peer0-org1:7052
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/Org1MSP/peer0.org1.net
volumes:
- /var/run:/host/var/run
- $ARTIFACTS:/var/artifacts
ports:
- 7051:7051
- 7053:7053
postgres01:
container_name: postgres01
image: postgres
environment:
- POSTGRES_PASSWORD=docker
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
volumes:
- $ARTIFACTS/postgres01:/var/lib/postgresql/data
- $SCRIPTS/createdb.sql:/docker-entrypoint-initdb.d/1-createdb.sql
command: postgres
ports:
- 5432:5432
networks:
- openplatform
# ORG2
rca-org2:
extends:
file: nodebase.yaml
service: ca
container_name: rca-org2
restart: always
environment:
- HYPERLEDGER_VOL=/var/artifacts
- FABRIC_CA_SERVER_HOME=/var/artifacts/crypto-config/Org2MSP/ca/server
- FABRIC_CA_SERVER_CSR_CN=rca-org2
- FABRIC_CA_SERVER_CA_NAME=rca-org2
ports:
- 5055:5055
command: sh -c 'fabric-ca-server start -d -b rca-org2-admin:rca-org2-adminPW --cfg.affiliations.allowremove --cfg.identities.allowremove --port 5055'
volumes:
- $SCRIPTS:/setup
- $ARTIFACTS:/var/artifacts
peer0-org2:
extends:
file: nodebase.yaml
service: peer
container_name: peer0-org2
environment:
- CORE_PEER_ID=peer0-org2
- CORE_PEER_ADDRESS=peer0-org2:7251
- CORE_PEER_LISTENADDRESS=0.0.0.0:7251
- CORE_PEER_LOCALMSPID=Org2MSP
- CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/Org2MSP/peer0.org2.net/msp
- CORE_PEER_TLS_CERT_FILE=/var/artifacts/crypto-config/Org2MSP/peer0.org2.net/tls-msp/signcerts/cert.pem
- CORE_PEER_TLS_KEY_FILE=/var/artifacts/crypto-config/Org2MSP/peer0.org2.net/tls-msp/keystore/key.pem
- CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/Org2MSP/peer0.org2.net/tls-msp/tlscacerts/tls-0-0-0-0-5052.pem
# - CORE_PEER_GOSSIP_BOOTSTRAP=peer1-org2:7351
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0-org2:7251
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0-org2:7251
- CORE_PEER_CHAINCODEADDRESS=peer0-org2:7252
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7252
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/Org2MSP/peer0.org2.net
volumes:
- /var/run:/host/var/run
- $ARTIFACTS:/var/artifacts
ports:
- 7251:7251
- 7253:7253
postgres02:
container_name: postgres02
image: postgres
environment:
- POSTGRES_PASSWORD=docker
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
volumes:
- $ARTIFACTS/postgres02:/var/lib/postgresql/data
- $SCRIPTS/createdb.sql:/docker-entrypoint-initdb.d/1-createdb.sql
command: postgres
ports:
- 5442:5432
networks:
- openplatform
Organizations:
- &org0
Name: org0
ID: Org0MSP
MSPDir: /var/artifacts/crypto-config/Org0MSP/msp
Policies:
Readers:
Type: Signature
Rule: "OR('Org0MSP.member','Org1MSP.member','Org2MSP.member')"
Writers:
Type: Signature
Rule: "OR('Org0MSP.member','Org1MSP.member','Org2MSP.member')"
Admins:
Type: Signature
Rule: "OR('Org0MSP.admin')"
OrdererEndpoints:
- orderer0-org0:7050
- &org1
Name: org1
ID: Org1MSP
MSPDir: /var/artifacts/crypto-config/Org1MSP/msp
Policies:
Readers:
Type: Signature
Rule: "OR('Org0MSP.member','Org1MSP.member','Org1MSP.admin','Org1MSP.peer','Org1MSP.client')"
Writers:
Type: Signature
Rule: "OR('Org0MSP.member','Org1MSP.member','Org1MSP.admin','Org1MSP.peer','Org1MSP.client')"
Admins:
Type: Signature
Rule: "OR('Org1MSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('Org1MSP.member','Org1MSP.admin','Org1MSP.peer','Org1MSP.client')"
AnchorPeers:
- Host: peer0-org1
Port: 7051
- &org2
Name: org2
ID: Org2MSP
MSPDir: /var/artifacts/crypto-config/Org2MSP/msp
Policies:
Readers:
Type: Signature
Rule: "OR('Org0MSP.member','Org2MSP.member','Org2MSP.admin','Org2MSP.peer','Org2MSP.client')"
Writers:
Type: Signature
Rule: "OR('Org0MSP.member','Org2MSP.member','Org2MSP.admin','Org2MSP.peer','Org2MSP.client')"
Admins:
Type: Signature
Rule: "OR('Org2MSP.admin')"
Endorsement:
Type: Signature
Rule: "OR('Org2MSP.admin','Org2MSP.member','Org2MSP.peer','Org2MSP.client')"
AnchorPeers:
- Host: peer0-org2
Port: 7251
Capabilities:
Channel: &ChannelCapabilities
V2_0: true
Orderer: &OrdererCapabilities
V2_0: true
Application: &ApplicationCapabilities
V2_0: true
################################################################################
#
# SECTION: Application
#
# This section defines the values to encode into a config transaction or
# genesis block for application related parameters
#
################################################################################
Application: &ApplicationDefaults
# Organizations is the list of orgs which are defined as participants on
# the application side of the network
Organizations:
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
LifecycleEndorsement:
Type: ImplicitMeta
Rule: 'MAJORITY Endorsement'
Endorsement:
Type: ImplicitMeta
Rule: 'MAJORITY Endorsement'
Capabilities:
<<: *ApplicationCapabilities
Orderer: &OrdererDefaults
OrdererType: etcdraft
Addresses:
- orderer0-org0:7050
BatchTimeout: 2s
BatchSize:
MaxMessageCount: 500
AbsoluteMaxBytes: 99 MB
PreferredMaxBytes: 2 MB
MaxChannels: 10
EtcdRaft:
Consenters:
- Host: orderer0-org0
Port: 7050
ClientTLSCert: /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/signcerts/cert.pem
ServerTLSCert: /var/artifacts/crypto-config/Org0MSP/orderer0.org0.com/tls-msp/signcerts/cert.pem
Options:
TickInterval: 500ms
ElectionTick: 10
HeartbeatTick: 1
MaxInflightBlocks: 5
SnapshotIntervalSize: 20 MB
Organizations:
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
BlockValidation:
Type: ImplicitMeta
Rule: "ANY Writers"
Channel: &ChannelDefaults
Policies:
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
Capabilities:
<<: *ChannelCapabilities
Profiles:
OrgsOrdererGenesis:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
Organizations:
- *org0
Capabilities:
<<: *OrdererCapabilities
Consortiums:
SampleConsortium:
Organizations:
- *org1
- *org2
OrgsChannel:
Consortium: SampleConsortium
<<: *ChannelDefaults
Application:
<<: *ApplicationDefaults
Organizations:
- *org1
- *org2
Capabilities:
<<: *ApplicationCapabilities
#!/usr/bin/env bash
################################
# Run local development network
################################
. ./scripts/setup.sh
COMPOSE="-f $COMPOSE_2ORG"
SECONDS=0
./cleanup.sh
./bootstrap.sh "$COMPOSE" "org0" "org1" "org2" "2org"
duration=$SECONDS
printf "${GREEN}$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed.\n\n${NC}"
version: '2'
services:
ca:
image: hyperledger/fabric-ca:1.4.6
environment:
- FABRIC_CA_SERVER_TLS_ENABLED=true
- FABRIC_CA_SERVER_CSR_HOSTS=0.0.0.0
- FABRIC_CA_SERVER_DEBUG=false
networks:
- openplatform
orderer:
image: hyperledger/fabric-orderer:$IMAGE_TAG
environment:
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_LOGLEVEL=INFO
- ORDERER_DEBUG_BROADCASTTRACEDIR=/var/artifacts/orderer/data/logs
networks:
- openplatform
peer:
image: hyperledger/fabric-peer:$IMAGE_TAG
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=dev-net-fab2_openplatform
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- CORE_PEER_PROFILE_ENABLED=true
networks:
- openplatform
cli:
image: hyperledger/fabric-tools:$IMAGE_TAG
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_TLS_ENABLED=true
networks:
- openplatform
#!/usr/bin/env bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
# $1 - message to be printed
# $2 - exit code of the previous operation
printMessage() {
MESSAGE=$1
CODE=$2
if [ $2 -ne 0 ] ; then
printf "${RED}${MESSAGE} failed${NC}\n"
exit -1
fi
printf "${GREEN}Complete ${MESSAGE}${NC}\n\n"
sleep 1
}
# $1 - code of org (e.g. "org1")
getConfig() {
case $1 in
org0)
NAME="Org0"
PEER="orderer0"
DOMAIN="org0.com"
CAPORT=5052
PORT=7050
GATEWAY="-"
IMAGE="-"
;;
org1)
NAME="Org1"
PEER="peer0"
DOMAIN="org1.net"
CAPORT=5054
PORT=7051
GATEWAY="gw-org1"
IMAGE=fabric-es/gw-org1:1.0
;;
org2)
NAME="Org2"
PEER="peer0"
DOMAIN="org2.net"
CAPORT=5055
PORT=7251
GATEWAY="gw-org2"
IMAGE=fabric-es/gw-org2:1.0
;;
org3)
NAME="Org3"
PEER="peer0"
DOMAIN="org3.net"
CAPORT=5056
PORT=7451
GATEWAY="gw-org3"
IMAGE=fabric-es/gw-org3:1.0
;;
esac
}
# $1 - container name
# $2 - command
# $3 - expected
containerWait() {
FOUND=false
COUNT=30
while [[ ("$FOUND"=false) && (COUNT -gt 0) ]]; do
RESULT=$(docker container exec -i $1 "$2" | grep -e "$3")
echo -n "."
if [ ! -z "$RESULT" ]; then
FOUND=true
printf "${GREEN}psql: connected to server ${1}${NC}\n"
break
fi
COUNT=$(( COUNT - 1 ))
sleep 1
done
if [ $COUNT -le 0 ]; then
printf "${RED}waiting for container $1 timed out${NC}\n"
fi
}
export VERSION=1.0
export IMAGE_TAG=2.0.1
export CONFIG=./config
export VOLUME=./volume
export ARTIFACTS=./artifacts
export SCRIPTS=./scripts
export CHAINCODE=../../packages/chaincode
export CRYPTO=/var/artifacts/crypto-config
export CURRENT_DIR=$PWD
export ROOT_DIR=$PWD/../..
export MEMBERS="'Org1MSP.member','Org2MSP.member'"
export AUTH_IMAGE=fabric-es/auth-server:1.0
export COMPOSE_2ORG=compose.2org.yaml
export COMPOSE_2ORG_AUTH=compose.2org.auth.yaml
export COMPOSE_2ORG_GW=compose.2org.gw.yaml
export COMPOSE_3ORG=compose.3org.yaml
export COMPOSE_3ORG_AUTH=compose.3org.auth.yaml
export COMPOSE_3ORG_GW=compose.3org.gw.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment