Skip to content

Commit b4d101b

Browse files
committed
[FAB-3161] /examples/cluster
The purpose of this patch is to provide a tool that will demonstrate how to assemble a complete cluster of a v1.0 architecture system, complete with security. It currently supports docker-compose (via "make compose") but future plans including adding "make kubernetes", etc. Usage =========== $ make Usage: make [target] Supported Targets: - compose-up [options]: builds a docker-compose based cluster [options: TLS=[true|false] (default: true)] - compose-down: shuts down a docker-compose based cluster - clean: cleans local artifacts and, where applicable, destroys cluster - help: displays this help message Example: make compose-up TLS=false Prerequisites: - Ensure you run "make docker" in both fabric.git and fabric-ca.git prior to execution Notes =================== The resulting cluster is not production-grade, per se, largely because of the way the keys are generated all in one place via cryptogen tool. However, there are some contexts in which this might be ok anyway (e.g. loading kubernetes secrets) and at the very least, its a prescription for the major steps needed. You may think of this tool as similar to e2e but with slightly different goals. E2E is targetted at easily standing up a fixed configuration and ensuring chaincode may deploy. This is targetted at easily standing up a dynamically generated crypto configuration in a somewhat realistic manner in a few different environments. Change-Id: I16561aa252212ca20645fa5b4a1a89ffd70c1a78 Signed-off-by: Gregory Haskins <[email protected]>
1 parent bc0cf92 commit b4d101b

File tree

9 files changed

+1031
-0
lines changed

9 files changed

+1031
-0
lines changed

examples/cluster/Makefile

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
PEERS += $(patsubst %,peer%,$(shell seq 1 4))
2+
NODES += $(PEERS)
3+
NODES += orderer
4+
NODES += cli
5+
NODES += ca
6+
7+
CHANNEL_NAME ?= mychannel
8+
9+
CRYPTOOUTPUT = build/cryptogen
10+
ORDERER_ORG = $(CRYPTOOUTPUT)/ordererOrganizations/orderer.net
11+
PEER_ORG= $(CRYPTOOUTPUT)/peerOrganizations/org1.net
12+
13+
CA_PATH = $(PEER_ORG)/ca
14+
ORDERER_PATH = $(ORDERER_ORG)/orderers
15+
PEER_PATH = $(PEER_ORG)/peers
16+
USERS_PATH = $(PEER_ORG)/users
17+
18+
CHANNEL_TXNS=build/channel.tx build/anchor.tx
19+
20+
mspmap.orderer := $(ORDERER_PATH)/orderer.orderer.net
21+
mspmap.peer1 := $(PEER_PATH)/peer1.org1.net
22+
mspmap.peer2 := $(PEER_PATH)/peer2.org1.net
23+
mspmap.peer3 := $(PEER_PATH)/peer3.org1.net
24+
mspmap.peer4 := $(PEER_PATH)/peer4.org1.net
25+
mspmap.cli := $(USERS_PATH)/[email protected]
26+
27+
COMPOSE=docker-compose -f compose/docker-compose.yaml
28+
DRUN=$(COMPOSE) run --rm cli
29+
30+
TLS ?= true
31+
export TLS_ENABLED=$(TLS)
32+
33+
CRYPTOGEN=build/bin/cryptogen
34+
CONFIGTXGEN=build/bin/configtxgen
35+
36+
FABRICPKG=github.com/hyperledger/fabric
37+
pkgmap.cryptogen := $(FABRICPKG)/common/tools/cryptogen
38+
pkgmap.configtxgen := $(FABRICPKG)/common/configtx/tool/configtxgen
39+
40+
help:
41+
@cat usage.txt
42+
43+
compose-up: nodes
44+
$(COMPOSE) up -d ca $(PEERS)
45+
$(DRUN) ./configure.sh $(CHANNEL_NAME) "$(CHANNEL_TXNS)" "$(PEERS)" $(TLS)
46+
47+
compose-down:
48+
$(COMPOSE) down
49+
rm -rf build/nodes $(CRYPTOOUTPUT)
50+
51+
nodes: $(patsubst %,build/nodes/%,$(NODES))
52+
53+
$(CRYPTOOUTPUT): config/cryptogen.yaml $(CRYPTOGEN)
54+
@mkdir -p ${@D}
55+
$(CRYPTOGEN) generate --config $< --output $@
56+
57+
.PRECIOUS: %.yaml
58+
%.yaml:
59+
@mkdir -p ${@D}
60+
cp config/${@F} $@
61+
62+
%/genesis.block: build/configtx.yaml build/core.yaml $(CONFIGTXGEN)
63+
@mkdir -p ${@D}
64+
FABRIC_CFG_PATH=build $(CONFIGTXGEN) -profile SampleOrg -outputBlock $@
65+
66+
%.tx: build/configtx.yaml build/core.yaml $(CONFIGTXGEN)
67+
68+
%/channel.tx:
69+
@mkdir -p ${@D}
70+
FABRIC_CFG_PATH=build $(CONFIGTXGEN) -profile SampleChannel \
71+
-channelID ${CHANNEL_NAME} \
72+
-outputCreateChannelTx $@
73+
74+
%/anchor.tx:
75+
@mkdir -p ${@D}
76+
FABRIC_CFG_PATH=build $(CONFIGTXGEN) -profile SampleChannel \
77+
-channelID ${CHANNEL_NAME} \
78+
-outputAnchorPeersUpdate $@ \
79+
-asOrg Org1MSP
80+
81+
.PRECIOUS: %/msp
82+
%/msp: $(CRYPTOOUTPUT)
83+
$(eval NODE = ${patsubst build/nodes/%/msp,%,${@}})
84+
@mkdir -p ${@D}
85+
cp -R $(mspmap.${NODE})/* ${@D}
86+
87+
.PRECIOUS: build/bin/%
88+
build/bin/%:
89+
@mkdir -p ${@D}
90+
GOBIN=$(abspath ${@D}) go install $(pkgmap.${@F})
91+
92+
build/nodes/orderer: build/nodes/orderer/orderer.yaml
93+
build/nodes/orderer: build/nodes/orderer/genesis.block
94+
build/nodes/cli: $(CHANNEL_TXNS)
95+
96+
build/nodes/ca:
97+
@mkdir -p $@/tls
98+
cp $(CA_PATH)/*_sk $@/tls/ca.key
99+
cp $(CA_PATH)/*.pem $@/tls/ca.crt
100+
101+
build/nodes/%: build/nodes/%/msp build/nodes/%/configtx.yaml build/nodes/%/core.yaml
102+
@echo "Built $@"
103+
104+
clean: compose-down
105+
rm -rf build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
version: '2'
2+
3+
services:
4+
5+
ca:
6+
container_name: ca
7+
image: hyperledger/fabric-ca
8+
dns_search: .
9+
environment:
10+
- FABRIC_CA_SERVER_TLS_ENABLED=${TLS_ENABLED}
11+
- FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server/tls/ca.crt
12+
- FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server/tls/ca.key
13+
volumes:
14+
- ../build/nodes/ca/tls:/etc/hyperledger/fabric-ca-server/tls
15+
16+
orderer:
17+
container_name: orderer
18+
image: hyperledger/fabric-orderer
19+
dns_search: .
20+
environment:
21+
- ORDERER_GENERAL_TLS_ENABLED=${TLS_ENABLED}
22+
volumes:
23+
- ../build/nodes/orderer:/etc/hyperledger/fabric
24+
25+
peer1:
26+
container_name: peer1
27+
extends:
28+
file: peer-base/peer-base.yaml
29+
service: peer-base
30+
environment:
31+
- CORE_PEER_ID=peer1
32+
- CORE_PEER_ADDRESS=peer1:7051
33+
- CORE_PEER_GOSSIP_ENDPOINT=peer1:7051
34+
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.net:7051
35+
volumes:
36+
- ../build/nodes/peer1:/etc/hyperledger/fabric
37+
depends_on:
38+
- orderer
39+
40+
peer2:
41+
container_name: peer2
42+
extends:
43+
file: peer-base/peer-base.yaml
44+
service: peer-base
45+
environment:
46+
- CORE_PEER_ID=peer2
47+
- CORE_PEER_ADDRESS=peer2:7051
48+
- CORE_PEER_GOSSIP_ENDPOINT=peer2:7051
49+
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer2.org1.net:7051
50+
volumes:
51+
- ../build/nodes/peer2:/etc/hyperledger/fabric
52+
depends_on:
53+
- orderer
54+
- peer1
55+
56+
peer3:
57+
container_name: peer3
58+
extends:
59+
file: peer-base/peer-base.yaml
60+
service: peer-base
61+
environment:
62+
- CORE_PEER_ID=peer3
63+
- CORE_PEER_ADDRESS=peer3:7051
64+
- CORE_PEER_GOSSIP_ENDPOINT=peer3:7051
65+
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer3.org1.net:7051
66+
volumes:
67+
- ../build/nodes/peer3:/etc/hyperledger/fabric
68+
depends_on:
69+
- orderer
70+
- peer1
71+
72+
peer4:
73+
container_name: peer4
74+
extends:
75+
file: peer-base/peer-base.yaml
76+
service: peer-base
77+
environment:
78+
- CORE_PEER_ID=peer4
79+
- CORE_PEER_ADDRESS=peer4:7051
80+
- CORE_PEER_GOSSIP_ENDPOINT=peer4:7051
81+
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer4.org1.net:7051
82+
volumes:
83+
- ../build/nodes/peer4:/etc/hyperledger/fabric
84+
depends_on:
85+
- orderer
86+
- peer1
87+
88+
cli:
89+
image: hyperledger/fabric-peer
90+
dns_search: .
91+
environment:
92+
- CORE_PEER_TLS_ENABLED=${TLS_ENABLED}
93+
- CORE_NEXT=true
94+
- CORE_LOGGING_LEVEL=DEBUG
95+
volumes:
96+
- ../build/nodes/cli:/etc/hyperledger/fabric
97+
- ..:/cli
98+
working_dir: /cli
99+
depends_on:
100+
- orderer
101+
- peer1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '2'
2+
services:
3+
peer-base:
4+
image: hyperledger/fabric-peer
5+
dns_search: .
6+
environment:
7+
- CORE_PEER_TLS_ENABLED=${TLS_ENABLED}
8+
- CORE_LOGGING_LEVEL=DEBUG
9+
- CORE_NEXT=true
10+
- CORE_PEER_ENDORSER_ENABLED=true
11+
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1:7051
12+
volumes:
13+
- /var/run/docker.sock:/var/run/docker.sock
14+
command: peer node start --peer-defaultchain=false

examples/cluster/config/configtx.yaml

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
---
2+
################################################################################
3+
#
4+
# Profile
5+
#
6+
# - Different configuration profiles may be encoded here to be specified
7+
# as parameters to the configtxgen tool
8+
#
9+
################################################################################
10+
Profiles:
11+
12+
SampleOrg:
13+
Orderer:
14+
<<: *OrdererDefaults
15+
Organizations:
16+
- *OrdererOrg
17+
Application:
18+
<<: *ApplicationDefaults
19+
Organizations:
20+
- *Org1
21+
Consortiums:
22+
SampleConsortium:
23+
Organizations:
24+
- *OrdererOrg
25+
- *Org1
26+
27+
SampleChannel:
28+
Consortium: SampleConsortium
29+
Application:
30+
Organizations:
31+
- *Org1
32+
33+
################################################################################
34+
#
35+
# Section: Organizations
36+
#
37+
# - This section defines the different organizational identities which will
38+
# be referenced later in the configuration.
39+
#
40+
################################################################################
41+
Organizations:
42+
43+
# SampleOrg defines an MSP using the sampleconfig. It should never be used
44+
# in production but may be used as a template for other definitions
45+
- &OrdererOrg
46+
# DefaultOrg defines the organization which is used in the sampleconfig
47+
# of the fabric.git development environment
48+
Name: OrdererOrg
49+
50+
# ID to load the MSP definition as
51+
ID: OrdererMSP
52+
53+
# MSPDir is the filesystem path which contains the MSP configuration
54+
MSPDir: cryptogen/ordererOrganizations/orderer.net/msp
55+
56+
AdminPrincipal: Role.ADMIN
57+
58+
# BCCSP (Blockchain crypto provider): Select which crypto implementation or
59+
# library to use
60+
BCCSP:
61+
Default: SW
62+
SW:
63+
Hash: SHA2
64+
Security: 256
65+
# Location of Key Store. If this is unset, a location will
66+
# be chosen using 'MSPDir'/keystore
67+
FileKeyStore:
68+
KeyStore:
69+
70+
- &Org1
71+
# DefaultOrg defines the organization which is used in the sampleconfig
72+
# of the fabric.git development environment
73+
Name: Org1MSP
74+
75+
# ID to load the MSP definition as
76+
ID: Org1MSP
77+
78+
MSPDir: cryptogen/peerOrganizations/org1.net/msp
79+
80+
AdminPrincipal: Role.ADMIN
81+
82+
# BCCSP (Blockchain crypto provider): Select which crypto implementation or
83+
# library to use
84+
BCCSP:
85+
Default: SW
86+
SW:
87+
Hash: SHA2
88+
Security: 256
89+
# Location of Key Store. If this is unset, a location will
90+
# be chosen using 'MSPDir'/keystore
91+
FileKeyStore:
92+
KeyStore:
93+
94+
AnchorPeers:
95+
# AnchorPeers defines the location of peers which can be used
96+
# for cross org gossip communication. Note, this value is only
97+
# encoded in the genesis block in the Application section context
98+
- Host: peer1
99+
Port: 7051
100+
101+
################################################################################
102+
#
103+
# SECTION: Orderer
104+
#
105+
# - This section defines the values to encode into a config transaction or
106+
# genesis block for orderer related parameters
107+
#
108+
################################################################################
109+
Orderer: &OrdererDefaults
110+
111+
# Orderer Type: The orderer implementation to start
112+
# Available types are "solo" and "kafka"
113+
OrdererType: solo
114+
115+
Addresses:
116+
- orderer:7050
117+
118+
# Batch Timeout: The amount of time to wait before creating a batch
119+
BatchTimeout: 2s
120+
121+
# Batch Size: Controls the number of messages batched into a block
122+
BatchSize:
123+
124+
# Max Message Count: The maximum number of messages to permit in a batch
125+
MaxMessageCount: 10
126+
127+
# Absolute Max Bytes: The absolute maximum number of bytes allowed for
128+
# the serialized messages in a batch.
129+
AbsoluteMaxBytes: 99 MB
130+
131+
# Preferred Max Bytes: The preferred maximum number of bytes allowed for
132+
# the serialized messages in a batch. A message larger than the preferred
133+
# max bytes will result in a batch larger than preferred max bytes.
134+
PreferredMaxBytes: 512 KB
135+
136+
Kafka:
137+
# Brokers: A list of Kafka brokers to which the orderer connects
138+
# NOTE: Use IP:port notation
139+
Brokers:
140+
- 127.0.0.1:9092
141+
142+
# Organizations is the list of orgs which are defined as participants on
143+
# the orderer side of the network
144+
Organizations:
145+
146+
################################################################################
147+
#
148+
# SECTION: Application
149+
#
150+
# - This section defines the values to encode into a config transaction or
151+
# genesis block for application related parameters
152+
#
153+
################################################################################
154+
Application: &ApplicationDefaults
155+
156+
# Organizations is the list of orgs which are defined as participants on
157+
# the application side of the network
158+
Organizations:

0 commit comments

Comments
 (0)