From 5c997421882f9ac3dc6f250f0a1c06ff6bee5987 Mon Sep 17 00:00:00 2001 From: Greg Haskins Date: Wed, 10 May 2017 21:50:07 -0400 Subject: [PATCH] [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: Admin@org1.net 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 --- examples/cluster/Makefile | 2 +- examples/cluster/compose/report-env.sh | 72 ++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/examples/cluster/Makefile b/examples/cluster/Makefile index 6755f5041cf..d49abab1917 100644 --- a/examples/cluster/Makefile +++ b/examples/cluster/Makefile @@ -46,7 +46,7 @@ compose-up: nodes @echo "Booting docker-compose environment" $(COMPOSE) up -d $(DAEMONS) $(DRUN) ./configure.sh $(CHANNEL_NAME) "$(CHANNEL_TXNS)" "$(PEERS)" $(TLS) - @./compose/report-env.sh "$(DAEMONS)" + @./compose/report-env.sh "$(DAEMONS)" build/client.config $(TLS) compose-down: $(COMPOSE) down diff --git a/examples/cluster/compose/report-env.sh b/examples/cluster/compose/report-env.sh index 7147aa281ae..20ef203ed25 100755 --- a/examples/cluster/compose/report-env.sh +++ b/examples/cluster/compose/report-env.sh @@ -1,6 +1,8 @@ #!/bin/bash NODES=$1 +CONFIG=$2 +TLS=$3 getip() { HOST=$1 @@ -8,14 +10,84 @@ getip() { docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $HOST } +url() { + TYPE=$1 + NODE=$2 + PORT=$3 + + if [ "$TLS" == "true" ]; then + TYPE="$1s" + fi + + echo $TYPE://$(getip $NODE):$PORT +} + +http() { + NODE=$1 + PORT=$2 + + echo $(url "http" $NODE $PORT) +} + +grpc() { + NODE=$1 + PORT=$2 + + echo $(url "grpc" $NODE $PORT) +} + +peerurls() { + for i in $(seq 1 4); do + echo "$(url grpc peer$i, 7051)" + done +} + generate_hosts() { for NODE in $NODES; do echo "$(getip $NODE) $NODE" done } +includefile() { + file=$1 + prefix=$2 + + echo "|" + + while IFS= read -r line; do + printf '%s%s\n' "$prefix" "$line" + done < "$file" +} + echo "========================================================================" echo "Cluster ready!" echo "========================================================================" echo generate_hosts | sort + +cat < $CONFIG +# +# Generated by fabric.git/examples/cluster. DO NOT EDIT! +# +ca: + url: $(http "ca" "7054") + certificate: $(includefile build/nodes/cli/tls/ca.crt " ") + +orderer: + url: $(grpc "orderer" "7050") + hostname: orderer + ca: $(includefile build/nodes/orderer/tls/ca.crt " ") + +peers: +$(for i in $(seq 1 4); do + echo " - api: $(grpc peer$i 7051)" + echo " events: $(grpc peer$i 7053)" + echo " hostname: peer$i" +done) + +identity: + principal: Admin@org1.net + mspid: Org1MSP + privatekey: $(includefile build/nodes/cli/tls/server.key " ") + certificate: $(includefile build/nodes/cli/tls/server.crt " ") +EOF