Update official scripts and docs
parent
1d3d6a3e54
commit
90dd7fee2f
|
@ -1,8 +1,8 @@
|
|||
# Hyperledger fabric 1.0
|
||||
|
||||
Here we give steps on how to setup a fabric 1.0 cluster, and then use it to run chaincode tests.
|
||||
Here we show steps on how to setup a fabric 1.0 network, and then use it to run chaincode tests.
|
||||
|
||||
If you're not familiar with Docker and Blockchain, can have a look at 2 books (in CN):
|
||||
If you're not familiar with Docker and Blockchain technology yet, feel free to have a look at 2 books (in CN):
|
||||
|
||||
* [Docker Practice](https://github.com/yeasy/docker_practice)
|
||||
* [Blockchain Guide](https://github.com/yeasy/blockchain_guide)
|
||||
|
@ -11,7 +11,7 @@ If you're not familiar with Docker and Blockchain, can have a look at 2 books (i
|
|||
|
||||
tldr :)
|
||||
|
||||
With Ubuntu/Debian, you can simple use the following scripts to setup the environment and start the fabric network.
|
||||
With Linxu (e.g., Ubuntu/Debian) and MacOS, you can simple use the following scripts to setup the environment and start a 4 peer (belonging to 2 organizations) fabric network.
|
||||
|
||||
```sh
|
||||
$ bash scripts/setup_Docker.sh # Install Docker, Docker-Compose
|
||||
|
@ -19,109 +19,9 @@ $ bash scripts/setup_Docker.sh # Install Docker, Docker-Compose
|
|||
bash scripts/start_fabric.sh
|
||||
```
|
||||
|
||||
If you want to setup the environment manually, then can follow the below steps in this section.
|
||||
|
||||
### Download Images
|
||||
|
||||
Pull necessary images of peer, orderer, ca, and base image.
|
||||
|
||||
```sh
|
||||
$ bash scripts/cleanup_env.sh
|
||||
$ bash scripts/download_images.sh
|
||||
```
|
||||
|
||||
There are also some community [images](https://hub.docker.com/r/hyperledger/) at Dockerhub, use at your own choice.
|
||||
If you want to setup the environment manually, then have a look at [manually setup](docs/setup.md).
|
||||
|
||||
|
||||
### Bootup and test Fabric 1.0
|
||||
|
||||
Start a fabric cluster.
|
||||
|
||||
```bash
|
||||
$ bash scripts/start_fabric.sh
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
$ docker-compose -f docker-compose-2orgs-4peers.yaml up
|
||||
```
|
||||
|
||||
Check the output log that the peer is connected to the ca and orderer successfully.
|
||||
|
||||
There will be 7 running containers, include 4 peers, 1 cli, 1 ca and 1 orderer.
|
||||
|
||||
```bash
|
||||
$ docker ps -a
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
8683435422ca hyperledger/fabric-peer "bash -c 'while true;" 19 seconds ago Up 18 seconds 7050-7059/tcp fabric-cli
|
||||
f284c4dd26a0 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 19 seconds 7050/tcp, 0.0.0.0:7051->7051/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com
|
||||
95fa3614f82c hyperledger/fabric-ca "fabric-ca-server sta" 22 seconds ago Up 19 seconds 0.0.0.0:7054->7054/tcp fabric-ca
|
||||
833ca0d8cf41 hyperledger/fabric-orderer "orderer" 22 seconds ago Up 19 seconds 0.0.0.0:7050->7050/tcp orderer.example.com
|
||||
cd21cfff8298 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com
|
||||
372b583b3059 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com
|
||||
47ce30077276 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
|
||||
```
|
||||
|
||||
#### Initialize fabric network
|
||||
|
||||
Into the container fabric-cli and run the initialize.sh script, this will prepare the basic environment required for chaincode operations,
|
||||
inclode `create channel`, `join channel`, `install` and `instantiate`. this script only needs to be executed once.
|
||||
|
||||
|
||||
```bash
|
||||
$ docker exec -it fabric-cli bash
|
||||
$ bash ./scripts/initialize.sh
|
||||
```
|
||||
|
||||
You should see the following output:
|
||||
|
||||
```bash
|
||||
2017-06-09 10:13:01.015 UTC [main] main -> INFO 00c Exiting.....
|
||||
===================== Chaincode Instantiation on PEER2 on channel 'businesschannel' is successful =====================
|
||||
|
||||
|
||||
===================== All GOOD, initialization completed =====================
|
||||
|
||||
|
||||
_____ _ _ ____
|
||||
| ____| | \ | | | _ \
|
||||
| _| | \| | | | | |
|
||||
| |___ | |\ | | |_| |
|
||||
|_____| |_| \_| |____/
|
||||
```
|
||||
|
||||
#### Chaincode Operations
|
||||
|
||||
After initialize network, you can execute some chaincode operations, such as `query` or `invoke`,
|
||||
and you can modify the parameters and execute this script repeatedly.
|
||||
|
||||
```bash
|
||||
$ bash ./scripts/test_4peers.sh #execute in container fabric-cli
|
||||
```
|
||||
|
||||
You should see the following output:
|
||||
|
||||
```bash
|
||||
UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
|
||||
UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
|
||||
UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AB7070A6D08031A0C08C3EAE9C90510...6D7963631A0A0A0571756572790A0161
|
||||
UTC [msp/identity] Sign -> DEBU 007 Sign: digest: FA308EF50C4812BADB60D58CE15C1CF41089EFB93B27D46885D92C92F55E98A0
|
||||
Query Result: 80
|
||||
UTC [main] main -> INFO 008 Exiting.....
|
||||
===================== Query on PEER3 on channel 'businesschannel' is successful =====================
|
||||
|
||||
===================== All GOOD, End-2-End execution completed =====================
|
||||
|
||||
|
||||
_____ _ _ ____
|
||||
| ____| | \ | | | _ \
|
||||
| _| | \| | | | | |
|
||||
| |___ | |\ | | |_| |
|
||||
|_____| |_| \_| |____/
|
||||
```
|
||||
|
||||
So far, we have quickly started a fabric network successfully.
|
||||
|
||||
## More to explore
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ services:
|
|||
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
|
||||
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
|
||||
volumes:
|
||||
#- ./e2e_cli/examples:/opt/gopath/src/github.com/hyperledger/fabric/examples
|
||||
- ./e2e_cli/examples:/opt/gopath/src/github.com/hyperledger/fabric/examples
|
||||
- ./e2e_cli/crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
|
||||
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
|
||||
- ./e2e_cli/channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
## Chaincode Tests
|
||||
|
||||
All the test command needs to be executed inside the `fabric-cli` container.
|
||||
|
||||
Use the following command to login into the container fabric-cli
|
||||
|
||||
```bash
|
||||
$ docker exec -it fabric-cli bash
|
||||
```
|
||||
|
||||
After executing the cmd, you can logout by `exit`.
|
||||
|
||||
### Initialize fabric network
|
||||
|
||||
Execute the `initialize.sh` script to
|
||||
|
||||
* create a new application channel
|
||||
* join all peers into the channel
|
||||
* install and instantiate chaincodes for testing
|
||||
|
||||
This script only needs to be executed once.
|
||||
|
||||
```bash
|
||||
$ bash ./scripts/initialize.sh
|
||||
```
|
||||
|
||||
You should see result like the following if the initialization is successful.
|
||||
|
||||
```bash
|
||||
==============================================
|
||||
==========initialize businesschannel==========
|
||||
==============================================
|
||||
|
||||
Channel name : businesschannel
|
||||
Creating channel...
|
||||
|
||||
...
|
||||
UTC [main] main -> INFO 00c Exiting.....
|
||||
===================== Chaincode Instantiation on PEER2 on channel 'businesschannel' is successful =====================
|
||||
|
||||
|
||||
===================== All GOOD, initialization completed =====================
|
||||
|
||||
|
||||
_____ _ _ ____
|
||||
| ____| | \ | | | _ \
|
||||
| _| | \| | | | | |
|
||||
| |___ | |\ | | |_| |
|
||||
|_____| |_| \_| |____/
|
||||
```
|
||||
|
||||
And there will be new chaincode container generated in the system
|
||||
|
||||
### Chaincode Operations
|
||||
|
||||
After initialize network, you can execute some chaincode operations, such as `query` or `invoke`,
|
||||
and you can modify the parameters and execute this script repeatedly.
|
||||
|
||||
```bash
|
||||
$ bash ./scripts/test_4peers.sh #execute in container fabric-cli
|
||||
```
|
||||
|
||||
You should see the following output:
|
||||
|
||||
```bash
|
||||
UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
|
||||
UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
|
||||
UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AB7070A6D08031A0C08C3EAE9C90510...6D7963631A0A0A0571756572790A0161
|
||||
UTC [msp/identity] Sign -> DEBU 007 Sign: digest: FA308EF50C4812BADB60D58CE15C1CF41089EFB93B27D46885D92C92F55E98A0
|
||||
Query Result: 80
|
||||
UTC [main] main -> INFO 008 Exiting.....
|
||||
===================== Query on PEER3 on channel 'businesschannel' is successful =====================
|
||||
|
||||
===================== All GOOD, End-2-End execution completed =====================
|
||||
|
||||
|
||||
_____ _ _ ____
|
||||
| ____| | \ | | | _ \
|
||||
| _| | \| | | | | |
|
||||
| |___ | |\ | | |_| |
|
||||
|_____| |_| \_| |____/
|
||||
```
|
||||
|
||||
So far, we have quickly started a fabric network successfully.
|
|
@ -0,0 +1,52 @@
|
|||
## Manually Setup
|
||||
|
||||
|
||||
### Install Docker/Docker-Compose
|
||||
|
||||
```sh
|
||||
$ bash scripts/setup_Docker.sh # Install Docker, Docker-Compose
|
||||
```
|
||||
|
||||
### Download Images
|
||||
|
||||
Pull necessary images of peer, orderer, ca, and base image. You may optionally run the clean_env.sh script to remove all existing container and images.
|
||||
|
||||
```sh
|
||||
$ bash scripts/cleanup_env.sh
|
||||
$ bash scripts/download_images.sh
|
||||
```
|
||||
|
||||
There are also some community [images](https://hub.docker.com/r/hyperledger/) at Dockerhub, use at your own choice.
|
||||
|
||||
|
||||
### Bootup Fabric Network
|
||||
|
||||
Start a fabric network with 4 peers belongs to 2 organizations.
|
||||
|
||||
```bash
|
||||
$ bash scripts/start_fabric.sh
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
$ docker-compose -f docker-compose-2orgs-4peers.yaml up
|
||||
```
|
||||
|
||||
Check the output log that the peer is connected to the ca and orderer successfully.
|
||||
|
||||
There will be 7 running containers, include 4 peers, 1 cli, 1 ca and 1 orderer.
|
||||
|
||||
```bash
|
||||
$ docker ps -a
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
8683435422ca hyperledger/fabric-peer "bash -c 'while true;" 19 seconds ago Up 18 seconds 7050-7059/tcp fabric-cli
|
||||
f284c4dd26a0 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 19 seconds 7050/tcp, 0.0.0.0:7051->7051/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com
|
||||
95fa3614f82c hyperledger/fabric-ca "fabric-ca-server sta" 22 seconds ago Up 19 seconds 0.0.0.0:7054->7054/tcp fabric-ca
|
||||
833ca0d8cf41 hyperledger/fabric-orderer "orderer" 22 seconds ago Up 19 seconds 0.0.0.0:7050->7050/tcp orderer.example.com
|
||||
cd21cfff8298 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com
|
||||
372b583b3059 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com
|
||||
47ce30077276 hyperledger/fabric-peer "peer node start --pe" 22 seconds ago Up 20 seconds 7050/tcp, 7052/tcp, 7054-7059/tcp, 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
|
||||
```
|
||||
|
||||
Now you can try chaincode operations with the bootup fabric network.
|
|
@ -25,7 +25,7 @@ services:
|
|||
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
|
||||
command: orderer
|
||||
volumes:
|
||||
- ../channel-artifacts/orderer.genesis.block:/var/hyperledger/orderer/orderer.genesis.block
|
||||
- ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
|
||||
- ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
|
||||
- ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
|
||||
ports:
|
||||
|
@ -39,6 +39,7 @@ services:
|
|||
environment:
|
||||
- CORE_PEER_ID=peer0.org1.example.com
|
||||
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
|
||||
- CORE_PEER_CHAINCODELISTENADDRESS=peer0.org1.example.com:7052
|
||||
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
|
||||
- CORE_PEER_LOCALMSPID=Org1MSP
|
||||
volumes:
|
||||
|
@ -47,6 +48,7 @@ services:
|
|||
- ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
|
||||
ports:
|
||||
- 7051:7051
|
||||
- 7052:7052
|
||||
- 7053:7053
|
||||
|
||||
peer1.org1.example.com:
|
||||
|
@ -57,6 +59,7 @@ services:
|
|||
environment:
|
||||
- CORE_PEER_ID=peer1.org1.example.com
|
||||
- CORE_PEER_ADDRESS=peer1.org1.example.com:7051
|
||||
- CORE_PEER_CHAINCODELISTENADDRESS=peer1.org1.example.com:7052
|
||||
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:7051
|
||||
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
|
||||
- CORE_PEER_LOCALMSPID=Org1MSP
|
||||
|
@ -67,6 +70,7 @@ services:
|
|||
|
||||
ports:
|
||||
- 8051:7051
|
||||
- 8052:7052
|
||||
- 8053:7053
|
||||
|
||||
peer0.org2.example.com:
|
||||
|
@ -77,6 +81,7 @@ services:
|
|||
environment:
|
||||
- CORE_PEER_ID=peer0.org2.example.com
|
||||
- CORE_PEER_ADDRESS=peer0.org2.example.com:7051
|
||||
- CORE_PEER_CHAINCODELISTENADDRESS=peer0.org2.example.com:7052
|
||||
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
|
||||
- CORE_PEER_LOCALMSPID=Org2MSP
|
||||
volumes:
|
||||
|
@ -85,6 +90,7 @@ services:
|
|||
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
|
||||
ports:
|
||||
- 9051:7051
|
||||
- 9052:7052
|
||||
- 9053:7053
|
||||
|
||||
peer1.org2.example.com:
|
||||
|
@ -95,6 +101,7 @@ services:
|
|||
environment:
|
||||
- CORE_PEER_ID=peer1.org2.example.com
|
||||
- CORE_PEER_ADDRESS=peer1.org2.example.com:7051
|
||||
- CORE_PEER_CHAINCODELISTENADDRESS=peer1.org2.example.com:7052
|
||||
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:7051
|
||||
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:7051
|
||||
- CORE_PEER_LOCALMSPID=Org2MSP
|
||||
|
@ -104,4 +111,5 @@ services:
|
|||
- ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls
|
||||
ports:
|
||||
- 10051:7051
|
||||
- 10052:7052
|
||||
- 10053:7053
|
||||
|
|
|
@ -125,10 +125,13 @@ Orderer: &OrdererDefaults
|
|||
PreferredMaxBytes: 512 KB
|
||||
|
||||
Kafka:
|
||||
# Brokers: A list of Kafka brokers to which the orderer connects
|
||||
# NOTE: Use IP:port notation
|
||||
# Brokers: A list of Kafka brokers to which the orderer connects. Edit
|
||||
# this list to identify the brokers of the ordering service.
|
||||
# NOTE: Use IP:port notation.
|
||||
Brokers:
|
||||
- 127.0.0.1:9092
|
||||
- kafka0:9092
|
||||
- kafka1:9092
|
||||
- kafka2:9092
|
||||
|
||||
# Organizations is the list of orgs which are defined as participants on
|
||||
# the orderer side of the network
|
||||
|
|
|
@ -57,7 +57,7 @@ services:
|
|||
command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'
|
||||
volumes:
|
||||
- /var/run/:/host/var/run/
|
||||
#- ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
|
||||
- ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
|
||||
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
|
||||
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
|
||||
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
|
||||
|
|
|
@ -907,3 +907,7 @@ back and recreate your channel artifacts.
|
|||
|
||||
- If you continue to see errors, share your logs on the **# fabric-questions**
|
||||
channel on `Hyperledger Rocket Chat <https://chat.hyperledger.org/home>`__.
|
||||
|
||||
.. Licensed under Creative Commons Attribution 4.0 International License
|
||||
https://creativecommons.org/licenses/by/4.0/
|
||||
|
||||
|
|
|
@ -52,9 +52,13 @@ function removeUnwantedImages() {
|
|||
}
|
||||
|
||||
function networkUp () {
|
||||
#Generate all the artifacts that includes org certs, orderer genesis block,
|
||||
# channel configuration transaction
|
||||
source generateArtifacts.sh $CH_NAME
|
||||
if [ -f "./crypto-config" ]; then
|
||||
echo "crypto-config directory already exists."
|
||||
else
|
||||
#Generate all the artifacts that includes org certs, orderer genesis block,
|
||||
# channel configuration transaction
|
||||
source generateArtifacts.sh $CH_NAME
|
||||
fi
|
||||
|
||||
if [ "${IF_COUCHDB}" == "couchdb" ]; then
|
||||
CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH up -d 2>&1
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright London Stock Exchange Group All Rights Reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
echo
|
||||
echo " ____ _____ _ ____ _____ _____ ____ _____ "
|
||||
echo "/ ___| |_ _| / \ | _ \ |_ _| | ____| |___ \ | ____|"
|
||||
|
@ -36,7 +39,6 @@ setGlobals () {
|
|||
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
|
||||
else
|
||||
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
|
||||
fi
|
||||
else
|
||||
CORE_PEER_LOCALMSPID="Org2MSP"
|
||||
|
|
Loading…
Reference in New Issue