Enable makefile support
parent
c31e41578a
commit
ed917fc719
|
@ -0,0 +1,33 @@
|
|||
COMPOSE_FILE="docker-compose-2orgs-4peers.yaml"
|
||||
|
||||
all:
|
||||
make start
|
||||
sleep 3
|
||||
make init
|
||||
sleep 3
|
||||
make test
|
||||
sleep 3
|
||||
make stop
|
||||
|
||||
setup: # setup the environment
|
||||
bash scripts/setup_Docker.sh # Install Docker, Docker-Compose
|
||||
bash scripts/download_images.sh # Pull required Docker images
|
||||
|
||||
start: # bootup the fabric network
|
||||
docker-compose -f ${COMPOSE_FILE} up -d # Start a fabric network
|
||||
|
||||
init: # initialize the fabric network
|
||||
docker exec -it fabric-cli bash ./scripts/test_4peers.sh
|
||||
|
||||
test: # test chaincode
|
||||
docker exec -it fabric-cli bash ./scripts/initialize.sh
|
||||
|
||||
stop: # stop the fabric network
|
||||
docker-compose -f ${COMPOSE_FILE} down # Stop a fabric network
|
||||
|
||||
clean: # clean up environment
|
||||
bash scripts/clean_env.sh
|
||||
|
||||
|
||||
show: # show existing docker images
|
||||
docker ps -qa
|
|
@ -7,23 +7,116 @@ If you're not familiar with Docker and Blockchain technology yet, feel free to h
|
|||
* [Docker Practice](https://github.com/yeasy/docker_practice)
|
||||
* [Blockchain Guide](https://github.com/yeasy/blockchain_guide)
|
||||
|
||||
## Setup
|
||||
|
||||
## Pass-through
|
||||
|
||||
The following command will run the entire process pass-through.
|
||||
|
||||
```sh
|
||||
$ make
|
||||
```
|
||||
|
||||
tldr :)
|
||||
|
||||
The following scripts will setup the environment and start a 4 peer (belonging to 2 organizations) fabric network.
|
||||
Otherwise, if u wanna know more or run the command manually, then go on reading the following part.
|
||||
|
||||
## Environment Setup
|
||||
|
||||
The following scripts will setup the environment by installing Docker, Docker-Compose and download required docker images.
|
||||
|
||||
```sh
|
||||
$ bash scripts/setup_Docker.sh # Install Docker, Docker-Compose
|
||||
bash scripts/download_images.sh # Pull required Docker images
|
||||
bash scripts/start_fabric.sh
|
||||
$ make setup # setup environment
|
||||
```
|
||||
|
||||
If you want to setup the environment manually, then have a look at [manually setup](docs/setup.md).
|
||||
|
||||
## Bootup Fabric Network
|
||||
|
||||
Start a 4 peer (belonging to 2 organizations) fabric network.
|
||||
|
||||
```sh
|
||||
$ make start # Start a fabric network
|
||||
```
|
||||
The script actually uses docker-compose to boot up the fabric network with several containers.
|
||||
|
||||
There will be 7 running containers, include 4 peers, 1 cli, 1 ca and 1 orderer.
|
||||
|
||||
```bash
|
||||
$ make show
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
1dc3f2557bdc hyperledger/fabric-tools "bash -c 'while tr..." 25 minutes ago Up 25 minutes fabric-cli
|
||||
5e5f37a0ed3c hyperledger/fabric-peer "peer node start" 25 minutes ago Up 25 minutes 7050/tcp, 7054-7059/tcp, 0.0.0.0:8051->7051/tcp, 0.0.0.0:8052->7052/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
|
||||
6cce94da6392 hyperledger/fabric-peer "peer node start" 25 minutes ago Up 25 minutes 7050/tcp, 7054-7059/tcp, 0.0.0.0:9051->7051/tcp, 0.0.0.0:9052->7052/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com
|
||||
e36c5e8d56c5 hyperledger/fabric-peer "peer node start" 25 minutes ago Up 25 minutes 7050/tcp, 7054-7059/tcp, 0.0.0.0:7051-7053->7051-7053/tcp peer0.org1.example.com
|
||||
1fdd3d2b6527 hyperledger/fabric-orderer "orderer start" 25 minutes ago Up 25 minutes 0.0.0.0:7050->7050/tcp orderer.example.com
|
||||
8af323340651 hyperledger/fabric-ca "fabric-ca-server ..." 25 minutes ago Up 25 minutes 0.0.0.0:7054->7054/tcp fabric-ca
|
||||
e41d8bca7fe5 hyperledger/fabric-peer "peer node start" 25 minutes ago Up 25 minutes 7050/tcp, 7054-7059/tcp, 0.0.0.0:10051->7051/tcp, 0.0.0.0:10052->7052/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com
|
||||
```
|
||||
|
||||
### Initialize Fabric network
|
||||
|
||||
```bash
|
||||
$ make init # Start a fabric network
|
||||
```
|
||||
|
||||
The command actually calls the `./scripts/initialize.sh` script in the `fabric-cli` container 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.
|
||||
|
||||
You should see result like the following if the initialization is successful.
|
||||
|
||||
```bash
|
||||
==============================================
|
||||
==========initialize businesschannel==========
|
||||
==============================================
|
||||
|
||||
Channel name : businesschannel
|
||||
Creating channel...
|
||||
|
||||
...
|
||||
|
||||
===================== All GOOD, initialization completed =====================
|
||||
```
|
||||
|
||||
And there will be new chaincode container generated in the system, looks like
|
||||
|
||||
```bash
|
||||
$ make show
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
9971c9fd1971 dev-peer1.org2.example.com-mycc-1.0 "chaincode -peer.a..." 54 seconds ago Up 53 seconds dev-peer1.org2.example.com-mycc-1.0
|
||||
e3092961b81b dev-peer1.org1.example.com-mycc-1.0 "chaincode -peer.a..." About a minute ago Up About a minute dev-peer1.org1.example.com-mycc-1.0
|
||||
57d3555f56e5 dev-peer0.org2.example.com-mycc-1.0 "chaincode -peer.a..." About a minute ago Up About a minute dev-peer0.org2.example.com-mycc-1.0
|
||||
c9974dbc21d9 dev-peer0.org1.example.com-mycc-1.0 "chaincode -peer.a..." 23 minutes ago Up 23 minutes dev-peer0.org1.example.com-mycc-1.0
|
||||
```
|
||||
|
||||
|
||||
## Test Chaincode
|
||||
|
||||
See [chaincode test](docs/chaincode_test.md).
|
||||
```bash
|
||||
$ make test # test with chaincode
|
||||
```
|
||||
|
||||
More details, see [chaincode test](docs/chaincode_test.md).
|
||||
|
||||
|
||||
## Stop the network
|
||||
|
||||
```bash
|
||||
$ make stop # stop the fabric network
|
||||
```
|
||||
|
||||
## Clean environment
|
||||
|
||||
Clean all related containers and images.
|
||||
|
||||
```bash
|
||||
$ make clean # clean the environment
|
||||
```
|
||||
|
||||
|
||||
## More to learn
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ services:
|
|||
image: hyperledger/fabric-tools
|
||||
tty: true
|
||||
environment:
|
||||
- GOPATH=/opt/gopath
|
||||
#- GOPATH=/opt/gopath
|
||||
- CORE_PEER_ID=fabric-cli
|
||||
- CORE_LOGGING_LEVEL=DEBUG
|
||||
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051 # default to operate on peer0.org1
|
||||
|
|
|
@ -8,52 +8,12 @@ Use the following command to login into the container fabric-cli
|
|||
$ docker exec -it fabric-cli bash
|
||||
```
|
||||
|
||||
After executing the cmd, you can logout by `exit`.
|
||||
After finish the chaincode tests, you can log-out 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`,
|
||||
You can execute some chaincode operations, such as `query` or `invoke`,
|
||||
and you can modify the parameters and execute this script repeatedly.
|
||||
|
||||
```bash
|
||||
|
@ -72,13 +32,4 @@ 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.
|
||||
|
|
|
@ -21,7 +21,9 @@ bea1154c7162 hyperledger/fabric-ca "fabric-ca-server ..." About
|
|||
|
||||
#### Create artifacts
|
||||
|
||||
**You can skip this step**, as we already put the needed artifacts `orderer.genesis.block` and `channel.tx` under `e2e_cli/channel-artifacts/`.
|
||||
**This step can be safely skipped.**.
|
||||
|
||||
As we already put the needed artifacts `orderer.genesis.block` and `channel.tx` under `e2e_cli/channel-artifacts/`.
|
||||
|
||||
Detailed steps in [GenerateArtifacts](artifacts_generation.md) explains the creation of `orderer.genesis.block` (needed by orderering service) and `channel.tx` (needed by cli to create new channel) and crypto related configuration files.
|
||||
|
||||
|
|
|
@ -18,35 +18,4 @@ $ 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.
|
||||
Now you can try [chaincode test](chaincode_test.md) operations with the bootup fabric network.
|
|
@ -14,32 +14,13 @@ else
|
|||
alias echo_b="echo"
|
||||
fi
|
||||
|
||||
while true
|
||||
do
|
||||
echo_b " ================== Clean up env ================\n"
|
||||
echo_b "1 Clean all containers"
|
||||
echo_b "2 Clean all chaincode-images"
|
||||
echo_r "3 [warning]Clean all hyperledger-images"
|
||||
echo_b "q quit"
|
||||
echo_b " ==================================\n"
|
||||
read -p "Choice the number and enter:" select
|
||||
echo_b "====================================\n"
|
||||
case $select in
|
||||
q|Q)
|
||||
break
|
||||
;;
|
||||
1)
|
||||
echo_b "Clean up all containers..."
|
||||
docker rm -f `docker ps -qa`
|
||||
;;
|
||||
2)
|
||||
echo_b "Clean up all chaincode-images..."
|
||||
docker rmi -f $(docker images |grep 'dev-peer*'|awk '{print $3}')
|
||||
;;
|
||||
3)
|
||||
echo_b "Clean up all hyperledger related images..."
|
||||
docker rmi $(docker images |grep 'hyperledger')
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo_b "Clean up all containers..."
|
||||
docker rm -f `docker ps -qa`
|
||||
|
||||
echo_b "Clean up all chaincode-images..."
|
||||
docker rmi -f $(docker images |grep 'dev-peer*'|awk '{print $3}')
|
||||
|
||||
echo_b "Clean up all hyperledger related images..."
|
||||
docker rmi $(docker images |grep 'hyperledger')
|
||||
|
||||
echo_g "Env cleanup done!"
|
|
@ -1,18 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Detecting whether can import the header file to render colorful cli output
|
||||
if [ -f ./header.sh ]; then
|
||||
source ./header.sh
|
||||
elif [ -f scripts/header.sh ]; then
|
||||
source scripts/header.sh
|
||||
else
|
||||
alias echo_r="echo"
|
||||
alias echo_g="echo"
|
||||
alias echo_b="echo"
|
||||
fi
|
||||
|
||||
COMPOSE_FILE=${1:-"docker-compose-2orgs-4peers.yaml"}
|
||||
|
||||
echo_b "Start up with ${COMPOSE_FILE}"
|
||||
|
||||
docker-compose -f ${COMPOSE_FILE} up -d
|
Loading…
Reference in New Issue