[開発] Hyplerledger Fabric Starter Kit での遊び方

Hyplerledger Fabric Starter Kit での遊び方
(近々整理予定)






Blockchain Hyplerledger Fabric Starter Kit
Azure Ubuntuで出来合いのChaincodeをデプロイするまでに実行した手順まとめ
==============================
1
環境構築
"Gitのインストール
Azure Ubuntuには不要"
"------------------------------
実施方法/確認方法"
"sudo apt-get install git
ーーーーーーーーーー
git --version"vi docker-compose.yml
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
2
環境構築
Goのインストール
"------------------------------
実施方法/確認方法"
"either one:
$ sudo apt install golang-go
$ apt-get update && apt-get install golang
ーーーーーーーーーー
$ go version"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
3
環境構築
"Goの作業フォルダ
"
"------------------------------
実施方法/確認方法"
StarterKitを動作させる分には無くてOK
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
4
環境構築
環境変数の設定
"------------------------------
実施方法/確認方法"
"export GOPATH=$HOME/gows
export PATH=$PATH:$GOPATH/bin
ーーーーーーーーーー
printenv"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
5
環境構築
環境更新
"------------------------------
実施方法/確認方法"
sudo apt-get update
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
6
環境構築
"wgetの取得
Azure Ubuntuには不要"
"------------------------------
実施方法/確認方法"
sudo apt-get install wget
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
7
環境構築
dockerのインストール
"------------------------------
実施方法/確認方法"
"$ wget -qO- https://get.docker.com/ | sh
$ sudo usermod -aG docker user1
ーーーーーーーーーー
docker-compose –v"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
8
環境構築
docker-composeのインストール
"------------------------------
実施方法/確認方法"
"$ sudo su
# curl -L https://github.com/docker/compose/releases/download/1.8.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
# exit
ーーーーーーーーーー
$ docker-compose version
$ docker-compose –v"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
9
環境設定 (任意)
fabricのインストール
"------------------------------
実施方法/確認方法"
"$ mkdir -p $HOME/gows/src/github.com/hyperledger
$ cd $HOME/gows/src/github.com/hyperledger
$ git clone https://github.com/hyperledger/fabric.git
以下を追記
DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
10
Vagrant担当の環境設定 (任意)
Rocks DBのインストール
"------------------------------
実施方法/確認方法"
"$ sudo apt-get install -y libsnappy-dev zlib1g-dev libbz2-dev
$ cd /tmp
$ git clone https://github.com/facebook/rocksdb.git
$ cd rocksdb
$ git checkout v4.1
諸設定
$ PORTABLE=1 make shared_lib
30分ほど待つ。
$ sudo INSTALL_PATH=/usr/local make install-shared

"
"------------------------------
実行結果"

"------------------------------
備考/参考"
"Building the fabric, Building outside of Vagrant,
https://github.com/hyperledger/fabric/blob/master/docs/dev-setup/build.md"
==============================
11
Vagrant担当の環境設定 (任意)
Pipのインストール
"------------------------------
実施方法/確認方法"
"$ curl -kL https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
$ sudo apt install python-pip
$ pip install --upgrade pip
$ sudo pip install behave nose docker-compose
$ sudo pip install -I flask==0.10.1 python-dateutil==2.2 pytz==2014.3 pyyaml==3.10 couchdb==1.0 flask-cors==2.0.1 requests==2.4.3
"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
12
Vagrant担当の環境設定 (任意)
docker daemonの初期値設定
"------------------------------
実施方法/確認方法"
"$ cd /etc/default/
$ sudo chmod 777 docker
$ vi docker

"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
13
Vagrant担当の環境設定 (任意)
Building on Z
"------------------------------
実施方法/確認方法"
"$ sudo su
$ sudo apt install yum
$ yum install git  skip as already installed
$ mkdir -p $HOME/git/src/github.com/hyperledger
$ git clone http://gerrit.hyperledger.org/r/fabric
$ source fabric/devenv/setupRHELonZ.sh
"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
14
設定
"docekr-compose
準備"
"------------------------------
実施方法/確認方法"
"$ cd $HOME
$ mkdir handon
$ cd handson
$ touch docker-compose.yml
$ vi docker-compose.yml
記載内容は本記事の最後に掲載
"
"------------------------------
実行結果"

"------------------------------
備考/参考"
"Writing, Building, and Running Chaincode in a Development Environment, Option 2 Docker for Mac or Windows, Running the Peer and CA,
https://github.com/hyperledger/fabric/blob/master/docs/Setup/Chaincode-setup.md"
==============================
15
起動
"docker-compose
起動"
"------------------------------
実施方法/確認方法"
"$ HOME/handson
$ docker-compose up –d
$ docker-compose up -d -f /home/user1/handson/docker-compose.yml
"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
16
終了
"docker-compose
終了"
"------------------------------
実施方法/確認方法"
docker-compose down -f /home/user1/handson/docker-compose.yml
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
17
動作確認
コンテナの物理ログファイル確認
"------------------------------
実施方法/確認方法"
"HOST VMの/var/lib/docker/containers//-json.log
$ sudo su
# cd /var/lib/docker/containers/"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
18
動作確認
コンテナのログ確認
"------------------------------
実施方法/確認方法"
"docker logs
e.g. $ docker logs vp0"
"------------------------------
実行結果"

"------------------------------
備考/参考"

==============================
19
動作確認
"RESTでピア確認
"
"------------------------------
実施方法/確認方法"
$ curl 172.17.0.2:7050/network/peers
"------------------------------
実行結果"

"------------------------------
備考/参考"
"REST API, REST Endpoints,
https://github.com/hyperledger/fabric/blob/master/docs/API/CoreAPI.md"
==============================
20
動作確認
"RESTでチェーンの長さ確認
"
"------------------------------
実施方法/確認方法"
"ピアだけが起動されている場合
$ curl 172.17.0.2:7050/chain
$ curl 172.17.0.2:7050/chain/blocks/1
CAも起動されている場合
$ curl 0.0.0.0:7050/chain
$ curl 0.0.0.0:7050/chain/blocks/1
$ curl http://localhost:7050/chain や
$ curl localhost:7050/chain でもOK
peerのCORE_VM_ENDPOINT環境変数を指定している場合
$ curl 172.17.0.1:7050/chain
$ curl 172.17.0.1:7050/chain/blocks/0
"
"------------------------------
実行結果"

"------------------------------
備考/参考"
"この時、127.17.0.2はNVPないしVPコンテナのIPで、7050はRESTが使用するポート。(core.yamlのrest.addressで定義あり)
ブロックの詳細を見る場合はindexを指定する。"
==============================
21
ログイン
CLIでログイン
"------------------------------
実施方法/確認方法"
"$ docker exec -it vp0 /bin/bash
# peer network login jim
Enter password for user 'jim': 6avZQLwcUe9b
もしくは
peer network login jim -p 6avZQLwcUe9b"
"------------------------------
実行結果"
"コンソール
user1@VM05:~$ docker exec -it vp0 /bin/bash
root@e6b94236f5b2:/opt/gopath/src/github.com/hyperledger/fabric# peer network login jim
00:19:14.835 [networkCmd] networkLogin -> INFO 001 CLI client login...
00:19:14.836 [networkCmd] networkLogin -> INFO 002 Local data store for client loginToken: /var/hyperledger/production/client/
Enter password for user 'jim': ************
00:19:41.629 [networkCmd] networkLogin -> INFO 003 Logging in user 'jim' on CLI interface...
00:19:41.975 [networkCmd] networkLogin -> INFO 004 Storing login token for user 'jim'.
00:19:41.975 [networkCmd] networkLogin -> INFO 005 Login successful for user 'jim'.
00:19:41.976 [main] main -> INFO 006 Exiting....."
"------------------------------
備考/参考"

==============================
22
ログイン
"RESTでログイン
※ HOST VMからでもピアコンテナからでも実行できる
※ CAコンテナとアプリコンテナからは実施不可。"
"------------------------------
実施方法/確認方法"
"curl -X POST -H 'Content-Type: application/json' -d '{"enrollId":"jim","enrollSecret":"6avZQLwcUe9b"}' http://localhost:7050/registrar
"
"------------------------------
実行結果"
"コンソール
{"OK":"Login successful for user 'jim'."}
ピアdockerログ
05:11:19.427 [rest] Register -> INFO 098 REST client login...
05:11:19.427 [rest] Register -> INFO 099 Local data store for client loginToken: /var/hyperledger/production/client/
05:11:19.427 [rest] Register -> INFO 09a Logging in user 'jim' on REST interface...
05:11:19.427 [crypto] RegisterClient -> INFO 09b Registering client [jim] with name [jim]...
05:11:19.433 [crypto] Debugf -> DEBU 09c [client.jim] Data will be stored at [/var/hyperledger/production/crypto/client/jim]
割愛
05:11:19.736 [crypto] RegisterClient -> INFO 0cb Registering client [jim] with name [jim]...done!
05:11:19.736 [rest] Register -> INFO 0cc Storing login token for user 'jim'.
05:11:19.737 [rest] Register -> INFO 0cd Login successful for user 'jim'."
"------------------------------
備考/参考"

==============================
23
ログアウト
RESTでログアウト
"------------------------------
実施方法/確認方法"
"HOSTVMで以下実行
user1@VM05:/opt$ curl -X DELETE --header 'Accept: application/json' 'http://localhost:7050/registrar/jim'"
"------------------------------
実行結果"
"コンソール
{"OK":"Deleted login token and directory for user jim."}
"
"------------------------------
備考/参考"

==============================
24
デプロイ
"RESTでCCデプロイ
(出来合いのCC)
※ HOSTVMかピアコンテナから実行
"
"------------------------------
実施方法/確認方法"
"echo '{
"jsonrpc": "2.0",
"method": "deploy",
"params": {
"type": 1,
"chaincodeID": {
"name": "mycc",
"path": "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
},
"ctorMsg": {
"function": "init",
"args": ["a", "1000", "b", "2000"]
},
"secureContext": "jim"
},
"id": 1
}' | curl -X POST -H 'Content-Type: application/json' -d @- http://localhost:7050/chaincode"
"------------------------------
実行結果"
"コンソール
{"jsonrpc":"2.0","result":{"status":"OK","message":"mycc"},"id":1}
ピアdockerログ
00:42:49.758 [rest] ProcessChaincode -> INFO 037 REST processing chaincode request...
00:42:49.758 [rest] processChaincodeDeploy -> INFO 038 REST deploying chaincode...
00:42:49.758 [rest] processChaincodeDeploy -> INFO 039 Local user 'jim' is already logged in. Retrieving login token.
00:42:49.759 [crypto] InitClient -> INFO 03a Initializing client [jim]...
00:42:50.084 [crypto] InitClient -> INFO 03b Initializing client [jim]...done!
00:42:50.085 [crypto] closeClientInternal -> INFO 03c Closing client [jim]...
00:42:50.171 [rest] processChaincodeDeploy -> INFO 03d Successfully deployed chainCode: mycc
00:42:50.171 [rest] ProcessChaincode -> INFO 03e REST successfully deploy chaincode: {"jsonrpc":"2.0","result":{"status":"OK","message":"mycc"},"id":1}"
"------------------------------
備考/参考"

==============================
25
デプロイ
"RESTでCCデプロイ
(出来合いのCC)
※ HOSTVMかピアコンテナから実行
※ cURLにヘッダ情報を載せなくてもOK"
"------------------------------
実施方法/確認方法"
"echo '{
"jsonrpc": "2.0", "method": "deploy",
"params": {
"type": 1,
"chaincodeID": {
"name": "mycc",
"language": "golang",
"path": "/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
},
"ctorMsg": {
"args": ["init", "a", "1000", "b", "2000"]
},
"secureContext": "jim"
},
"id": 0
}' | curl -X POST --data-binary @- 'http://localhost:7050/chaincode'
"
"------------------------------
実行結果"
{"jsonrpc":"2.0","result":{"status":"OK","message":"mycc"},"id":0}
"------------------------------
備考/参考"

==============================

26
デプロイ
"CLIでCCデプロイ
(出来合いのCC)"
"------------------------------
実施方法/確認方法"
"$ docker exec -it vp0 /bin/bash
# peer chaincode deploy -u jim -n mycc -c '{"Function":"init", "Args":[ "a", "2000", "b", "1000"] }'

実行引数にCパスを渡していないパターン
CCの在り処はdocker-compose.ymlのappに以下の定義を参照していると推測。
command: sh -c "sleep 20; /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/chaincode_example02""
"------------------------------
実行結果"
"コンソール
09:29:38.054 [chaincodeCmd] getChaincodeSpecification -> INFO 001 Local user 'jim' is already logged in. Retrieving login token.
09:29:38.800 [chaincodeCmd] chaincodeDeploy -> INFO 002 Deploy result: type:GOLANG chaincodeID: ctorMsg:
Deploy chaincode: mycc
09:29:38.800 [main] main -> INFO 003 Exiting....."
"------------------------------
備考/参考"
"ピアコンテナからCLIでデプロイする場合、ピアdockerログには認証のログしか出力されない。問題なくデプロイできた場合は、デプロイに関するINFO以上のログなし。
"
==============================
27
デプロイ
"CLIでCCデプロイ
(出来合いのCC)"
"------------------------------
実施方法/確認方法"
"$ docker exec -it vp0 /bin/bash
# peer chaincode deploy -u jim -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'

実行引数にCCパスを渡すパターン"
"------------------------------
実行結果"
"コンソール
Deploy chaincode: mycc
09:53:31.493 [main] main -> INFO 003 Exiting.....
ピアdockerログ
09:58:08.080 [chaincodeCmd] getChaincodeSpecification -> INFO 001 Local user 'jim' is already logged in. Retrieving login token.
09:58:08.508 [chaincodeCmd] chaincodeDeploy -> INFO 002 Deploy result: type:GOLANG chaincodeID: ctorMsg:
Deploy chaincode: mycc
09:58:08.508 [main] main -> INFO 003 Exiting....."
"------------------------------
備考/参考"

==============================
使用したdocker-compose.yml

myca:
# try 'docker ps' to see the container status after starting this compose
container_name: ca
image: hyperledger/fabric-membersrvc
# ports:
# - "7054:7054"
command: membersrvc

myvp0:
container_name: vp0
image: hyperledger/fabric-peer
ports:
# the ports allow access from outside container. alson, not needed when run a single container.
- "7050:7050"
- "7051:7051"
- "7053:7053"
environment:
- CORE_PEER_ADDRESSAUTODETECT=true
# comment in either one. both will give you a same result.
# 172.17.0.1 is a default docker0 bridge ip. see /etc/local/docker>DOCKER_OPTS for relevant setting.
- CORE_VM_ENDPOINT=unix:///var/run/docker.sock
# - CORE_VM_ENDPOINT=http://172.17.0.1:2375
- CORE_LOGGING_LEVEL=INFO
- CORE_PEER_ID=vp0
- CORE_PEER_PKI_ECA_PADDR=ca:7054
- CORE_PEER_PKI_TCA_PADDR=ca:7054
- CORE_PEER_PKI_TLSCA_PADDR=ca:7054
- CORE_SECURITY_ENABLED=true
# - CORE_SECURITY_ENROLLID=test_vp0
# - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
# choose either: noops or pbft
- CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=noops
# this gives access to the docker host daemon to deploy chain code in network mode
volumes:
- /var/run/docker.sock:/var/run/docker.sock
# have the peer wait 10 sec for membersrvc to start
# the following is to run the peer in Developer mode - also set sample DEPLOY_MODE=dev
command: sh -c "sleep 10; peer node start --peer-chaincodedev"
#command: sh -c "sleep 10; peer node start"
links:
- myca

# refer to hyperledger/fabric/docs/Setup/Network-setup.md

myapp:
container_name: app
image: hyperledger/fabric-starter-kit
# volumes:
# # tweak this to map a local developmnt directory tree into the container
# - ~/mytest:/user/mytest
environment:
# - MEMBERSRVC_ADDRESS=membersrvc:7054
# - PEER_ADDRESS=vp0:7051
# - KEY_VALUE_STORE=/tmp/hl_sdk_node_key_value_store
# # set to following to 'dev' if peer running in Developer mode
- DEPLOY_MODE=dev
- CORE_CHAINCODE_ID_NAME=mycc
- CORE_PEER_ADDRESS=vp0:7051
# the following command will start the chain code when this container starts and ready it for deployment by the app
command: sh -c "sleep 20; /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02/chaincode_example02"
# stdin_open: true
# tty: true
links:
- myca
- myvp0


tag : Blockchain Hyperledger Fabric Starter Kit Azure Ubuntu docker compose Vagrant

2016-11-12 13:50 : 開発 : コメント : 0 : トラックバック : 0 :
コメントの投稿
非公開コメント

« next  ホーム  prev »

search

ad



counter


tag cloud

category cloud