LoginSignup
8
6

More than 5 years have passed since last update.

Hyperledger Irohaをサクッとビルドする

Last updated at Posted at 2018-01-31

Hyperledger Irohaをサクッとビルドする

ブロックチェーン・プラットホームのHyperledger Irohaも昨年末にv1.0 alphaとして公開されています。公式では、Web上にドキュメントが公開されているのですが、サクッとビルドしてdockerコンテナを動かすことができるようにしてみました。

一応、免責事項をつけさせてください。

免責事項

このプログラムの使用等によって生じた、いかなる損害・損失に対しても作者は一切責任を負いません。

1. Hyperledger Irohaをクローンする

github.comでOSSとして公開されているHyperledger Irohaをクローンします。昨年末に公開されているリリースがv1.0_alphaですからチェックアウトしておきます。

$ git clone https://github.com/hyperledger/iroha.git
$ cd iroha
$ git checkout refs/tags/v1.0_alpha

2. iroha-piをクローンする

Hyperledger Irohaと同じディレクトリに、github.com からiroha-piをクローンします。

$ cd ..
$ git clone https://github.com/tkyonezu/iroha-pi.git

3. Hyperledger Irohaをビルドする

クローンしたiroha-piを使ってHyperledger Irohaをビルドします。

$ cd iroha-pi
$ make

iroha-pimakeを実行するとHyperledger Irohaのdockerコンテナが作成されます。

具体的には、次の内容を実行しています。

No 内容
1 Irohaビルド用のdockerコンテナを作成する。
2 Irohaビルド用のdockerコンテナでHyperledger Irohaをビルドする。
3 ビルドしたIrohaから、実行用のコマンド、ライブラリを抽出する。
4 抽出した実行用のコマンド、ライブラリで実行用のIrohaコンテナを作成する。

ビルドに成功すると、以下の2つのコンテナが作成されています。

$ docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
hyperledger/iroha-pi       latest              0aa91a722ab4        4 hours ago         789MB
hyperledger/iroha-pi-dev   latest              9c586f98ce2a        6 days ago          802MB

4. Hyperledger Irohaを起動する

iroha-piでは、docker-composeを使ってHyperledger Irohaを起動できます。

$ make up
Creating iroha_redis_1    ... done
Creating network "iroha_default" with the default driver
Creating iroha_postgres_1 ... done
Creating iroha_postgres_1 ...
Creating iroha_node_1     ... done

Hyperledger IrohaがRedisPostgreSQLを使っていますので、初回にはredispostgresのdockerコンテナがpullされます。

起動に成功していれば、次のようにログが表示されます。

$ make logs
docker logs -f iroha_node_1
[08:49:28][th: 8][info] [MAIN] << start
[08:49:28][th: 8][info] [MAIN] << config initialized
[08:49:28][th: 8][info] [IROHAD] << created
[08:49:28][th: 8][info] [StorageImpl:initConnection] << Start storage creation
[08:49:28][th: 8][info] [StorageImpl:initConnection] << block store created
[08:49:28][th: 8][info] [StorageImpl:initConnection] << connection to Redis completed
[08:49:28][th: 8][info] [StorageImpl:initConnection] << connection to PostgreSQL completed
[08:49:28][th: 8][info] [StorageImpl:initConnection] << transaction to PostgreSQL initialized
[08:49:28][th: 8][info] [IROHAD] << [Init] => storage
[08:49:28][th: 8][info] [StorageImpl] << Drop ledger
[08:49:28][th: 8][info] [StorageImpl] << drop dp
[08:49:28][th: 8][info] [StorageImpl] << drop redis
[08:49:28][th: 8][info] [StorageImpl] << drop block store
[08:49:28][th: 8][info] [MAIN] << Block is parsed
[08:49:28][th: 8][info] [MAIN] << Genesis block inserted, number of transactions: 1
[08:49:28][th: 8][info] [IROHAD] << [Init] => converters
[08:49:28][th: 8][info] [IROHAD] << [Init] => peer query
[08:49:28][th: 8][info] [IROHAD] << [Init] => crypto provider
[08:49:28][th: 8][info] [IROHAD] << [Init] => validators
[08:49:28][th: 8][info] [OrderingGate] << Subscribe
[08:49:28][th: 8][info] [IROHAD] << [Init] => init ordering gate - [true]
[08:49:28][th: 8][info] [IROHAD] << [Init] => init simulator
[08:49:28][th: 8][info] [IROHAD] << [Init] => block loader
[08:49:28][th: 8][info] [IROHAD] << [Init] => consensus gate
[08:49:28][th: 8][info] [IROHAD] << [Init] => synchronizer
[08:49:28][th: 8][info] [IROHAD] << [Init] => pcs
[08:49:28][th: 8][info] [IROHAD] << [Init] => command service
[08:49:28][th: 8][info] [IROHAD] << [Init] => query service
[08:49:28][th: 8][info] [MAIN] << Running iroha
[08:49:28][th: 8][info] [IROHAD] << ===> iroha initialized

Redis、PostgreSQLとの接続に成功して、最後にiroha initializedと表示されています。

5. Hyperledger Irohaを停止する

docker-composeで起動していますので、docker-compose downで停止します。make logs を実行している場合には-fオプションを使用していますから^Cで終了するか他の端末からmake downを実行します。

$ make down
env COMPOSE_PROJECT_NAME=iroha docker-compose -p iroha -f docker-compose.yml down
Stopping iroha_node_1     ... done
Stopping iroha_postgres_1 ... done
Stopping iroha_redis_1    ... done
Removing iroha_node_1     ... done
Removing iroha_postgres_1 ... done
Removing iroha_redis_1    ... done
Removing network iroha_default

環境によるかとは思いますが、クラウドで25分程度、Macで1時間半程度、ラズパイでも2時間40分程度でフルビルドできていました。
(Mac の Core i7 での HyperThreadingサポート入れてみたら、47分程度まで短縮されました)

昔々のUNIX導入手順書の最後に書いてあったように、パイでも食べてコーヒー飲みながらビルドできると良いなという思いでiroha-piという名前になっていたりします。

実際の使い方については、また機会があれば書いていきたいと思います。

8
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6