Skip to content

Commit 0f38dc1

Browse files
adnan-cdenyeart
authored andcommitted
[FAB-2565] Example docker-compose with CouchDB
https://jira.hyperledger.org/browse/FAB-2565 Including CouchDB option to an existing docker-compose file provided as example. Updating documentation to show how to activate the CouchDB option. Also, setting orderer batch-timeout to 2s to avoid timing issues during demonstrations. Change-Id: I8ab93bdf2acda3ea97669497b5231c97653436d1 Signed-off-by: Adnan Choudhury <[email protected]>
1 parent d7920a9 commit 0f38dc1

File tree

3 files changed

+219
-9
lines changed

3 files changed

+219
-9
lines changed

examples/e2e_cli/configtx.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Orderer: &OrdererDefaults
131131
- orderer0:7050
132132

133133
# Batch Timeout: The amount of time to wait before creating a batch
134-
BatchTimeout: 10s
134+
BatchTimeout: 2s
135135

136136
# Batch Size: Controls the number of messages batched into a block
137137
BatchSize:

examples/e2e_cli/docker-compose.yaml

+59-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ services:
2424
ports:
2525
- 7050:7050
2626

27+
## To enable CouchDB as state database, uncomment the following sections of this file:
28+
## 1) couchdb containers
29+
## 2) peer environment variables CORE_LEDGER_STATE_STATEDATABASE and
30+
## CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS
31+
## 3) couch container names in "depends_on" section
32+
33+
# couchdb0:
34+
# container_name: couchdb0
35+
# image: hyperledger/fabric-couchdb
36+
## Uncomment the port mapping if you want to expose the CouchDB service,
37+
## for example to utilize Fauxton User Interface in dev environments.
38+
# ports:
39+
# - "5984:5984"
40+
2741
peer0:
2842
container_name: peer0
2943
extends:
@@ -33,12 +47,14 @@ services:
3347
- CORE_PEER_ID=peer0
3448
- CORE_PEER_ADDRESS=peer0:7051
3549
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0:7051
36-
#- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer0:7050
50+
# - CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer0:7050
3751
- CORE_PEER_LOCALMSPID=Org0MSP
3852
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/signcerts/peer0Signer.pem
3953
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/msp/sampleconfig/keystore/peer0Signer.pem
4054
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/cacerts/peerOrg0.pem
41-
#- CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer0
55+
# - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer0
56+
# - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
57+
# - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb0:5984
4258
volumes:
4359
- /var/run/:/host/var/run/
4460
- ./crypto/peer/peer0/localMspConfig:/etc/hyperledger/fabric/msp/sampleconfig
@@ -47,6 +63,15 @@ services:
4763
- 7053:7053
4864
depends_on:
4965
- orderer0
66+
# - couchdb0
67+
68+
# couchdb1:
69+
# container_name: couchdb1
70+
# image: hyperledger/fabric-couchdb
71+
## Uncomment the port mapping if you want to expose the CouchDB service,
72+
## for example to utilize Fauxton User Interface in dev environments.
73+
# ports:
74+
# - "6984:5984"
5075

5176
peer1:
5277
container_name: peer1
@@ -58,12 +83,14 @@ services:
5883
- CORE_PEER_ADDRESS=peer1:7051
5984
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1:7051
6085
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0:7051
61-
#- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer0:7050
86+
# - CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer0:7050
6287
- CORE_PEER_LOCALMSPID=Org0MSP
6388
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/signcerts/peer1Signer.pem
6489
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/msp/sampleconfig/keystore/peer1Signer.pem
6590
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/cacerts/peerOrg0.pem
66-
#- CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer1
91+
# - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer1
92+
# - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
93+
# - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb1:5984
6794
volumes:
6895
- /var/run/:/host/var/run/
6996
- ./crypto/peer/peer1/localMspConfig:/etc/hyperledger/fabric/msp/sampleconfig
@@ -73,6 +100,15 @@ services:
73100
depends_on:
74101
- orderer0
75102
- peer0
103+
# - couchdb1
104+
105+
# couchdb2:
106+
# container_name: couchdb2
107+
# image: hyperledger/fabric-couchdb
108+
## Uncomment the port mapping if you want to expose the CouchDB service,
109+
## for example to utilize Fauxton User Interface in dev environments.
110+
# ports:
111+
# - "7984:5984"
76112

77113
peer2:
78114
container_name: peer2
@@ -90,6 +126,8 @@ services:
90126
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/msp/sampleconfig/keystore/peer2Signer.pem
91127
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/admincerts/peerOrg1.pem
92128
#- CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer2
129+
# - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
130+
# - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb2:5984
93131
volumes:
94132
- /var/run/:/host/var/run/
95133
- ./crypto/peer/peer2/localMspConfig:/etc/hyperledger/fabric/msp/sampleconfig
@@ -100,6 +138,15 @@ services:
100138
- orderer0
101139
- peer0
102140
- peer1
141+
# - couchdb2
142+
143+
# couchdb3:
144+
# container_name: couchdb3
145+
# image: hyperledger/fabric-couchdb
146+
## Uncomment the port mapping if you want to expose the CouchDB service,
147+
## for example to utilize Fauxton User Interface in dev environments.
148+
# ports:
149+
# - "8984:5984"
103150

104151
peer3:
105152
container_name: peer3
@@ -111,12 +158,14 @@ services:
111158
- CORE_PEER_ADDRESS=peer3:7051
112159
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer3:7051
113160
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0:7051
114-
#- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer0:7050
161+
# - CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer0:7050
115162
- CORE_PEER_LOCALMSPID=Org1MSP
116163
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/signcerts/peer3Signer.pem
117164
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/msp/sampleconfig/keystore/peer3Signer.pem
118165
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/msp/sampleconfig/cacerts/peerOrg1.pem
119-
#- CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer3
166+
# - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer3
167+
# - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
168+
# - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb3:5984
120169
volumes:
121170
- /var/run/:/host/var/run/
122171
- ./crypto/peer/peer3/localMspConfig:/etc/hyperledger/fabric/msp/sampleconfig
@@ -128,6 +177,7 @@ services:
128177
- peer0
129178
- peer1
130179
- peer2
180+
# - couchdb3
131181

132182
cli:
133183
container_name: cli
@@ -141,15 +191,15 @@ services:
141191
- CORE_NEXT=true
142192
- CORE_PEER_ID=cli
143193
- CORE_PEER_ENDORSER_ENABLED=true
144-
#- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer0:7050
194+
# - CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer0:7050
145195
- CORE_PEER_ADDRESS=peer0:7051
146196
- CORE_PEER_GOSSIP_IGNORESECURITY=true
147197
- CORE_PEER_LOCALMSPID=Org0MSP
148198
- CORE_PEER_TLS_ENABLED=true
149199
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig/signcerts/peer0Signer.pem
150200
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig/keystore/peer0Signer.pem
151201
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig/cacerts/peerOrg0.pem
152-
#- CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer0
202+
# - CORE_PEER_TLS_SERVERHOSTOVERRIDE=peer0
153203
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig
154204

155205
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
@@ -158,6 +208,7 @@ services:
158208
volumes:
159209
- /var/run/:/host/var/run/
160210
- ./examples/:/opt/gopath/src/github.com/hyperledger/fabric/examples/
211+
- ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
161212
- ./crypto:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
162213
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
163214
depends_on:

examples/e2e_cli/end-to-end.rst

+159
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,165 @@ run!
649649

650650
rm -rf /var/hyperledger/*
651651

652+
Using CouchDB
653+
-------------
654+
655+
The state database can be switched from the default (goleveldb) to CouchDB.
656+
The same chaincode functions are available with CouchDB, however, there is the
657+
added ability to perform rich and complex queries against the state database
658+
data content contingent upon the chaincode data being modeled as JSON.
659+
660+
To use CouchDB instead of the default database (goleveldb), follow the same
661+
procedure in the **Prerequisites** section, and additionally perform the
662+
following two steps to enable the CouchDB containers and associate each peer
663+
container with a CouchDB container:
664+
665+
- Make the CouchDB image.
666+
667+
.. code:: bash
668+
669+
# make sure you are in the /fabric directory
670+
make couchdb
671+
672+
- Open the ``fabric/examples/e2e_cli/docker-compose.yaml`` and un-comment
673+
all commented statements relating to CouchDB containers and peer container
674+
use of CouchDB. These instructions are are also outlined in the
675+
same ``docker-compose.yaml`` file. Search the file for 'couchdb' (case insensitive) references.
676+
677+
*chaincode_example02* should now work using CouchDB underneath.
678+
679+
***Note***: If you choose to implement mapping of the fabric-couchdb container
680+
port to a host port, please make sure you are aware of the security
681+
implications. Mapping of the port in a development environment allows the
682+
visualization of the database via the CouchDB web interface (Fauxton).
683+
Production environments would likely refrain from implementing port mapping in
684+
order to restrict outside access to the CouchDB containers.
685+
686+
You can use *chaincode_example02* chaincode against the CouchDB state database
687+
using the steps outlined above, however in order to exercise the query
688+
capabilities you will need to use a chaincode that has data modeled as JSON,
689+
(e.g. *marbles02*). You can locate the *marbles02* chaincode in the
690+
``fabric/examples/chaincode/go`` directory.
691+
692+
Install, instantiate, invoke, and query *marbles02* chaincode by following the
693+
same general steps outlined above for *chaincode_example02* in the **Manually
694+
create the channel and join peers through CLI** section . After the **Join
695+
channel** step, use the following steps to interact with the *marbles02*
696+
chaincode:
697+
698+
- Install and instantiate the chaincode in ``peer0`` (replace ``$ORDERER_IP``
699+
with the IP address of the orderer. One way to find the address is with the
700+
command ``docker inspect orderer | grep \"IPAddress\"``):
701+
702+
.. code:: bash
703+
704+
peer chaincode install -o $ORDERER_IP:7050 -n marbles -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/marbles02
705+
peer chaincode instantiate -o $ORDERER_IP:7050 -C $mychannel -n marbles -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/marbles02 -c '{"Args":["init"]}' -P "OR ('Org0MSP.member','Org1MSP.member')"
706+
707+
- Create some marbles and move them around:
708+
709+
.. code:: bash
710+
711+
peer chaincode invoke -o $ORDERER_IP:7050 -C mychannel -n marbles -c '{"Args":["initMarble","marble1","blue","35","tom"]}'
712+
peer chaincode invoke -o $ORDERER_IP:7050 -C mychannel -n marbles -c '{"Args":["initMarble","marble2","red","50","tom"]}'
713+
peer chaincode invoke -o $ORDERER_IP:7050 -C mychannel -n marbles -c '{"Args":["initMarble","marble3","blue","70","tom"]}'
714+
peer chaincode invoke -o $ORDERER_IP:7050 -C mychannel -n marbles -c '{"Args":["transferMarble","marble2","jerry"]}'
715+
peer chaincode invoke -o $ORDERER_IP:7050 -C mychannel -n marbles -c '{"Args":["transferMarblesBasedOnColor","blue","jerry"]}'
716+
peer chaincode invoke -o $ORDERER_IP:7050 -C mychannel -n marbles -c '{"Args":["delete","marble1"]}'
717+
718+
719+
720+
- If you chose to activate port mapping, you can now view the state database
721+
through the CouchDB web interface (Fauxton) by opening a browser and
722+
navigating to one of the two URLs below.
723+
724+
For containers running in a vagrant environment:
725+
726+
```http://localhost:15984/_utils```
727+
728+
For non-vagrant environment, use the port address that was mapped in CouchDB
729+
container specification:
730+
731+
```http://localhost:5984/_utils```
732+
733+
You should see a database named ``mychannel`` and the documents
734+
inside it.
735+
736+
- You can run regular queries from the `cli` (e.g. reading ``marble2``):
737+
738+
.. code:: bash
739+
740+
peer chaincode query -o $ORDERER_IP:7050 -C mychannel -n marbles -c '{"Args":["readMarble","marble2"]}'
741+
742+
743+
You should see the details of ``marble2``:
744+
745+
.. code:: bash
746+
747+
Query Result: {"color":"red","docType":"marble","name":"marble2","owner":"jerry","size":50}
748+
749+
750+
Retrieve the history of ``marble1``:
751+
752+
.. code:: bash
753+
754+
peer chaincode query -o $ORDERER_IP:7050 -C mychannel -n marbles -c '{"Args":["getHistoryForMarble","marble1"]}'
755+
756+
You should see the transactions on ``marble1``:
757+
758+
.. code:: bash
759+
760+
Query Result: [{"TxId":"1c3d3caf124c89f91a4c0f353723ac736c58155325f02890adebaa15e16e6464", "Value":{"docType":"marble","name":"marble1","color":"blue","size":35,"owner":"tom"}},{"TxId":"755d55c281889eaeebf405586f9e25d71d36eb3d35420af833a20a2f53a3eefd", "Value":{"docType":"marble","name":"marble1","color":"blue","size":35,"owner":"jerry"}},{"TxId":"819451032d813dde6247f85e56a89262555e04f14788ee33e28b232eef36d98f", "Value":}]
761+
762+
763+
764+
- You can also perform rich queries on the data content, such as querying marble fields by owner ``jerry``:
765+
766+
.. code:: bash
767+
768+
peer chaincode query -o $ORDERER_IP:7050 -C myc1 -n marbles -c '{"Args":["queryMarblesByOwner","jerry"]}'
769+
770+
The output should display the two marbles owned by ``jerry``:
771+
772+
.. code:: bash
773+
774+
Query Result: [{"Key":"marble2", "Record":{"color":"red","docType":"marble","name":"marble2","owner":"jerry","size":50}},{"Key":"marble3", "Record":{"color":"blue","docType":"marble","name":"marble3","owner":"jerry","size":70}}]
775+
776+
Query by field ``owner`` where the value is ``jerry``:
777+
778+
.. code:: bash
779+
780+
peer chaincode query -o $ORDERER_IP:7050 -C myc1 -n marbles -c '{"Args":["queryMarbles","{\"selector\":{\"owner\":\"jerry\"}}"]}'
781+
782+
The output should display:
783+
784+
.. code:: bash
785+
786+
Query Result: [{"Key":"marble2", "Record":{"color":"red","docType":"marble","name":"marble2","owner":"jerry","size":50}},{"Key":"marble3", "Record":{"color":"blue","docType":"marble","name":"marble3","owner":"jerry","size":70}}]
787+
788+
A Note on Data Persistence
789+
--------------------------
790+
791+
If data persistence is desired on the peer container or the CouchDB container,
792+
one option is to mount a directory in the docker-host into a relevant directory
793+
in the container. For example, you may add the following two lines in
794+
the peer container specification in the ``docker-compose.yaml`` file:
795+
796+
.. code:: bash
797+
798+
volumes:
799+
- /var/hyperledger/peer0:/var/hyperledger/production
800+
801+
802+
For the CouchDB container, you may add the following two lines in the CouchDB
803+
container specification:
804+
805+
.. code:: bash
806+
807+
volumes:
808+
- /var/hyperledger/couchdb0:/opt/couchdb/data
809+
810+
652811
Troubleshooting
653812
---------------
654813

0 commit comments

Comments
 (0)