Skip to content

Commit

Permalink
[FAB-4197][FAB-4198] examples/cluster improvements
Browse files Browse the repository at this point in the history
This patch enhances the examples/cluster facility as follows:

1) assets are now generated statically
2) We can use an arbitrary docker tag rather than assume :latest

(1) Means that "make compose" will now generate a docker-compose
configuration that may be used outside of the examples/cluster
environment.  E.g. once "make compose" completes, the user may
manage the docker-composition however they like.

(2) Means that we can now direct the tooling to generate arbibrary
tags (e.g. x86_64-1.0.0) rather than assuming :latest.  We also
added a few more knobs, like the ability to point to a completely
different docker namespace (with DOCKER_NS=hyperledger the default).

Fixes FAB-4197 and FAB-4198

Change-Id: Ibfac70680b4af5c119aa6e2e3adb01773378cfe0
Signed-off-by: Greg Haskins <[email protected]>
Signed-off-by: Gari Singh <[email protected]>
  • Loading branch information
ghaskins committed Aug 27, 2017
1 parent bd9411a commit 8cb5d21
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 73 deletions.
48 changes: 32 additions & 16 deletions examples/cluster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ mspmap.peer3 := $(PEER_PATH)/peer3.org1.net
mspmap.peer4 := $(PEER_PATH)/peer4.org1.net
mspmap.cli := $(USERS_PATH)/[email protected]

COMPOSE=docker-compose -f compose/docker-compose.yaml
DRUN=$(COMPOSE) run --rm cli

RELEASE ?= latest
CA_RELEASE ?= $(RELEASE)
FABRIC_RELEASE ?= $(RELEASE)
DOCKER_NS ?= hyperledger
TLS ?= true
export TLS_ENABLED=$(TLS)

CRYPTOGEN=build/bin/cryptogen
CONFIGTXGEN=build/bin/configtxgen
Expand All @@ -48,15 +48,8 @@ pkgmap.configtxgen := $(FABRICPKG)/common/configtx/tool/configtxgen
help:
@cat usage.txt

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)" build/client.config $(TLS)

compose-down:
$(COMPOSE) down
rm -rf build/nodes $(CRYPTOOUTPUT)
compose: nodes build/docker-compose.yaml build/compose-up.sh build/configure.sh
@echo "Build complete: run 'build/compose-up.sh'"

nodes: $(patsubst %,build/nodes/%,$(NODES))

Expand Down Expand Up @@ -117,6 +110,29 @@ build/nodes/tlsca: build/nodes/tlsca/fabric-tlsca-server-config.yaml
build/nodes/%: build/nodes/%/msp build/nodes/%/configtx.yaml build/nodes/%/core.yaml
@echo "Built $@"

clean: compose-down
rm -rf build
rm $(CHANNEL_NAME).block
build/docker-compose.yaml: compose/docker-compose.yaml.in
@mkdir -p $(@D)
cat $< \
| sed -e 's/_TLS_ENABLED_/${TLS}/g' \
| sed -e 's/_DOCKER_NS_/${DOCKER_NS}/g' \
| sed -e 's/_CA_RELEASE_/${CA_RELEASE}/g' \
| sed -e 's/_FABRIC_RELEASE_/${FABRIC_RELEASE}/g' \
> $@

build/compose-up.sh: compose/compose-up.sh.in
@mkdir -p $(@D)
cat $< \
| sed -e 's/_COMPOSE_DAEMONS_/${DAEMONS}/g' \
| sed -e 's/_COMPOSE_CHANNEL_NAME_/${CHANNEL_NAME}/g' \
| sed -e 's/_COMPOSE_PEERS_/${PEERS}/g' \
| sed -e 's/_COMPOSE_NODES_/${NODES}/g' \
| sed -e 's/_COMPOSE_TLS_/${TLS}/g' \
> $@
chmod +x $@

build/configure.sh: compose/configure.sh.in
cp $< $@

clean:
-rm -rf build
-rm $(CHANNEL_NAME).block
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
# SPDX-License-Identifier: Apache-2.0
#

set -e

NODES=$1
CONFIG=$2
TLS=$3
DAEMONS="_COMPOSE_DAEMONS_"
CHANNEL_NAME=_COMPOSE_CHANNEL_NAME_
PEERS="_COMPOSE_PEERS_"
NODES="_COMPOSE_NODES_"
TLS=_COMPOSE_TLS_

SCRIPTDIR=`dirname $0`
OUTPUT=${1:-$SCRIPTDIR/client.config}

getip() {
HOST=$1
Expand Down Expand Up @@ -49,7 +55,7 @@ peerurls() {
}

generate_hosts() {
for NODE in $NODES; do
for NODE in $DAEMONS; do
echo "$(getip $NODE) $NODE"
done
}
Expand All @@ -65,28 +71,38 @@ includefile() {
done < "$file"
}

echo "========================================================================"
echo "Launching Hyperledger Cluster via docker-compose"
echo "========================================================================"
docker-compose -f $SCRIPTDIR/docker-compose.yaml up -d $DAEMONS

echo "========================================================================"
echo "Configuring cluster"
echo "========================================================================"
(cd $SCRIPTDIR && docker-compose run --rm cli ./configure.sh $CHANNEL_NAME "channel.tx anchor.tx" "$PEERS" $TLS)

echo "========================================================================"
echo "Cluster ready!"
echo "========================================================================"
echo
generate_hosts | sort

cat <<EOF > $CONFIG
cat <<EOF > $OUTPUT
#
# Generated by fabric.git/examples/cluster. DO NOT EDIT!
#
ca:
url: $(http "ca" "7054")
certificate: $(includefile build/nodes/ca/ca.crt " ")
certificate: $(includefile $SCRIPTDIR/nodes/ca/ca.crt " ")
tlsca:
url: $(http "tlsca" "7054")
certificate: $(includefile build/nodes/tlsca/ca.crt " ")
certificate: $(includefile $SCRIPTDIR/nodes/tlsca/ca.crt " ")
orderer:
url: $(grpc "orderer" "7050")
hostname: orderer
ca: $(includefile build/nodes/orderer/tls/ca.crt " ")
ca: $(includefile $SCRIPTDIR/nodes/orderer/tls/ca.crt " ")
peers:
$(for i in $(seq 1 4); do
Expand All @@ -98,6 +114,8 @@ done)
identity:
principal: [email protected]
mspid: Org1MSP
privatekey: $(includefile build/nodes/cli/tls/server.key " ")
certificate: $(includefile build/nodes/cli/tls/server.crt " ")
privatekey: $(includefile $SCRIPTDIR/nodes/cli/tls/server.key " ")
certificate: $(includefile $SCRIPTDIR/nodes/cli/tls/server.crt " ")
EOF

echo "Output written to $OUTPUT"
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CHANNEL_TXNS=$2
PEERS=$3
TLS_ENABLED=$4

CA_CRT=build/cryptogen/ordererOrganizations/orderer.net/tlsca/tlsca.orderer.net-cert.pem
CA_CRT=cryptogen/ordererOrganizations/orderer.net/tlsca/tlsca.orderer.net-cert.pem

if [ "$TLS_ENABLED" == "true" ]; then
CREATE_OPTS="--tls --cafile $CA_CRT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,57 @@ services:

ca:
container_name: ca
image: hyperledger/fabric-ca
image: _DOCKER_NS_/fabric-ca:_CA_RELEASE_
dns_search: .
environment:
- FABRIC_CA_SERVER_TLS_ENABLED=${TLS_ENABLED}
- FABRIC_CA_SERVER_TLS_ENABLED=_TLS_ENABLED_
logging: &logging
driver: json-file
options:
max-size: "25m"
max-file: "2"
volumes:
- ../build/nodes/ca:/etc/hyperledger/fabric-ca-server
- ./nodes/ca:/etc/hyperledger/fabric-ca-server

tlsca:
container_name: tlsca
image: hyperledger/fabric-ca
image: _DOCKER_NS_/fabric-ca:_CA_RELEASE_
dns_search: .
environment:
- FABRIC_CA_SERVER_TLS_ENABLED=${TLS_ENABLED}
- FABRIC_CA_SERVER_TLS_ENABLED=_TLS_ENABLED_
logging:
<<: *logging
volumes:
- ../build/nodes/tlsca:/etc/hyperledger/fabric-ca-server
- ./nodes/tlsca:/etc/hyperledger/fabric-ca-server

orderer:
container_name: orderer
image: hyperledger/fabric-orderer
image: _DOCKER_NS_/fabric-orderer:_FABRIC_RELEASE_
dns_search: .
environment:
- ORDERER_GENERAL_TLS_ENABLED=${TLS_ENABLED}
- ORDERER_GENERAL_TLS_ENABLED=_TLS_ENABLED_
logging:
<<: *logging
volumes:
- ../build/nodes/orderer:/etc/hyperledger/fabric
- ./nodes/orderer:/etc/hyperledger/fabric
depends_on:
- ca

peer-base:
image: _DOCKER_NS_/fabric-peer:_FABRIC_RELEASE_
dns_search: .
environment:
- CORE_PEER_TLS_ENABLED=_TLS_ENABLED_
- CORE_LOGGING_LEVEL=WARNING
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1:7051
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=compose_default
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: peer node start

peer1:
container_name: peer1
extends:
file: peer-base/peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer1
Expand All @@ -58,14 +69,13 @@ services:
logging:
<<: *logging
volumes:
- ../build/nodes/peer1:/etc/hyperledger/fabric
- ./nodes/peer1:/etc/hyperledger/fabric
depends_on:
- orderer

peer2:
container_name: peer2
extends:
file: peer-base/peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer2
Expand All @@ -75,15 +85,14 @@ services:
logging:
<<: *logging
volumes:
- ../build/nodes/peer2:/etc/hyperledger/fabric
- ./nodes/peer2:/etc/hyperledger/fabric
depends_on:
- orderer
- peer1

peer3:
container_name: peer3
extends:
file: peer-base/peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer3
Expand All @@ -93,15 +102,14 @@ services:
logging:
<<: *logging
volumes:
- ../build/nodes/peer3:/etc/hyperledger/fabric
- ./nodes/peer3:/etc/hyperledger/fabric
depends_on:
- orderer
- peer1

peer4:
container_name: peer4
extends:
file: peer-base/peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer4
Expand All @@ -111,21 +119,21 @@ services:
logging:
<<: *logging
volumes:
- ../build/nodes/peer4:/etc/hyperledger/fabric
- ./nodes/peer4:/etc/hyperledger/fabric
depends_on:
- orderer
- peer1

cli:
image: hyperledger/fabric-peer
image: _DOCKER_NS_/fabric-peer:_FABRIC_RELEASE_
dns_search: .
environment:
- CORE_PEER_TLS_ENABLED=${TLS_ENABLED}
- CORE_PEER_TLS_ENABLED=_TLS_ENABLED_
- CORE_NEXT=true
- CORE_LOGGING_LEVEL=DEBUG
volumes:
- ../build/nodes/cli:/etc/hyperledger/fabric
- ..:/cli
- ./nodes/cli:/etc/hyperledger/fabric
- .:/cli
working_dir: /cli
depends_on:
- orderer
Expand Down
19 changes: 0 additions & 19 deletions examples/cluster/compose/peer-base/peer-base.yaml

This file was deleted.

23 changes: 17 additions & 6 deletions examples/cluster/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@ 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
- compose [options]: builds a docker-compose based cluster

options:
RELEASE=[string] (default: latest)
TLS=[true|false] (default: true)

notes:
Once complete, run the script
./build/compose-up.sh to start your
cluster

- clean: cleans local artifacts
- help: displays this help message

Example:

make compose-up TLS=false
make compose TLS=false RELEASE=x86_64-1.0.0

Prerequisites:
Notes:

- Ensure you run "make docker" in both fabric.git and fabric-ca.git prior to execution
Default RELEASE=latest requires you to manually ensure that the :latest tagged images are local. A
convenient way to do this is to run "make docker" in both fabric.git and fabric-ca.git prior to
execution.

Licensed under Creative Commons Attribution 4.0 International License
https://creativecommons.org/licenses/by/4.0/

0 comments on commit 8cb5d21

Please sign in to comment.