Skip to content

Commit

Permalink
[FAB-3954] /examples/cluster: add client config
Browse files Browse the repository at this point in the history
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 <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed May 18, 2017
1 parent 59dd7ba commit 5c99742
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/cluster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 72 additions & 0 deletions examples/cluster/compose/report-env.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,93 @@
#!/bin/bash

NODES=$1
CONFIG=$2
TLS=$3

getip() {
HOST=$1

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 <<EOF > $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

0 comments on commit 5c99742

Please sign in to comment.