Skip to content

Commit 5c99742

Browse files
committed
[FAB-3954] /examples/cluster: add client config
We want to make it as easy as possible for a client to consume a fabric configuration. This patch adds a new output "build/client.config". This file is a YAML formatted structure that can be consumed by a client. It contains details specific to the cluster that was created, such as IP, port, protocols, principals, and key material. These files may be consumed by fabric clients, which we will take advantage of elsewhere. ----------------------------------------------------------- ca: url: http://172.18.0.2:7054 certificate: | -----BEGIN CERTIFICATE----- MIICLTCCA...... -----END CERTIFICATE----- orderer: grpc://172.18.0.3:7050 peers: - api: grpc://172.18.0.4:7051 events: grpc://172.18.0.4:7053 hostname: peer1 - api: grpc://172.18.0.7:7051 events: grpc://172.18.0.7:7053 hostname: peer2 - api: grpc://172.18.0.6:7051 events: grpc://172.18.0.6:7053 hostname: peer3 - api: grpc://172.18.0.5:7051 events: grpc://172.18.0.5:7053 hostname: peer4 identity: principal: [email protected] mspid: Org1MSP privatekey: | -----BEGIN PRIVATE KEY----- MIGHAgEAM... -----END PRIVATE KEY----- certificate: | -----BEGIN CERTIFICATE----- MIICFjCCA... -----END CERTIFICATE----- ----------------------------------------------------------- Fixes FAB-3954 Change-Id: I96a20f57fc2a7502d8d132461dccb30e8da78c59 Signed-off-by: Greg Haskins <[email protected]>
1 parent 59dd7ba commit 5c99742

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

examples/cluster/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ compose-up: nodes
4646
@echo "Booting docker-compose environment"
4747
$(COMPOSE) up -d $(DAEMONS)
4848
$(DRUN) ./configure.sh $(CHANNEL_NAME) "$(CHANNEL_TXNS)" "$(PEERS)" $(TLS)
49-
@./compose/report-env.sh "$(DAEMONS)"
49+
@./compose/report-env.sh "$(DAEMONS)" build/client.config $(TLS)
5050

5151
compose-down:
5252
$(COMPOSE) down
+72
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,93 @@
11
#!/bin/bash
22

33
NODES=$1
4+
CONFIG=$2
5+
TLS=$3
46

57
getip() {
68
HOST=$1
79

810
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $HOST
911
}
1012

13+
url() {
14+
TYPE=$1
15+
NODE=$2
16+
PORT=$3
17+
18+
if [ "$TLS" == "true" ]; then
19+
TYPE="$1s"
20+
fi
21+
22+
echo $TYPE://$(getip $NODE):$PORT
23+
}
24+
25+
http() {
26+
NODE=$1
27+
PORT=$2
28+
29+
echo $(url "http" $NODE $PORT)
30+
}
31+
32+
grpc() {
33+
NODE=$1
34+
PORT=$2
35+
36+
echo $(url "grpc" $NODE $PORT)
37+
}
38+
39+
peerurls() {
40+
for i in $(seq 1 4); do
41+
echo "$(url grpc peer$i, 7051)"
42+
done
43+
}
44+
1145
generate_hosts() {
1246
for NODE in $NODES; do
1347
echo "$(getip $NODE) $NODE"
1448
done
1549
}
1650

51+
includefile() {
52+
file=$1
53+
prefix=$2
54+
55+
echo "|"
56+
57+
while IFS= read -r line; do
58+
printf '%s%s\n' "$prefix" "$line"
59+
done < "$file"
60+
}
61+
1762
echo "========================================================================"
1863
echo "Cluster ready!"
1964
echo "========================================================================"
2065
echo
2166
generate_hosts | sort
67+
68+
cat <<EOF > $CONFIG
69+
#
70+
# Generated by fabric.git/examples/cluster. DO NOT EDIT!
71+
#
72+
ca:
73+
url: $(http "ca" "7054")
74+
certificate: $(includefile build/nodes/cli/tls/ca.crt " ")
75+
76+
orderer:
77+
url: $(grpc "orderer" "7050")
78+
hostname: orderer
79+
ca: $(includefile build/nodes/orderer/tls/ca.crt " ")
80+
81+
peers:
82+
$(for i in $(seq 1 4); do
83+
echo " - api: $(grpc peer$i 7051)"
84+
echo " events: $(grpc peer$i 7053)"
85+
echo " hostname: peer$i"
86+
done)
87+
88+
identity:
89+
principal: [email protected]
90+
mspid: Org1MSP
91+
privatekey: $(includefile build/nodes/cli/tls/server.key " ")
92+
certificate: $(includefile build/nodes/cli/tls/server.crt " ")
93+
EOF

0 commit comments

Comments
 (0)