diff --git a/examples/cluster/Makefile b/examples/cluster/Makefile index b05c40e599e..7fb5c5a5b32 100644 --- a/examples/cluster/Makefile +++ b/examples/cluster/Makefile @@ -32,11 +32,11 @@ mspmap.peer3 := $(PEER_PATH)/peer3.org1.net mspmap.peer4 := $(PEER_PATH)/peer4.org1.net mspmap.cli := $(USERS_PATH)/Admin@org1.net -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 @@ -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)) @@ -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 diff --git a/examples/cluster/compose/report-env.sh b/examples/cluster/compose/compose-up.sh.in similarity index 53% rename from examples/cluster/compose/report-env.sh rename to examples/cluster/compose/compose-up.sh.in index 9c6e6d18a99..da8e5857f23 100755 --- a/examples/cluster/compose/report-env.sh +++ b/examples/cluster/compose/compose-up.sh.in @@ -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 @@ -49,7 +55,7 @@ peerurls() { } generate_hosts() { - for NODE in $NODES; do + for NODE in $DAEMONS; do echo "$(getip $NODE) $NODE" done } @@ -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 < $CONFIG +cat < $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 @@ -98,6 +114,8 @@ done) identity: principal: Admin@org1.net 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" diff --git a/examples/cluster/configure.sh b/examples/cluster/compose/configure.sh.in similarity index 85% rename from examples/cluster/configure.sh rename to examples/cluster/compose/configure.sh.in index e0a5cf0ca42..777dc534330 100755 --- a/examples/cluster/configure.sh +++ b/examples/cluster/compose/configure.sh.in @@ -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" diff --git a/examples/cluster/compose/docker-compose.yaml b/examples/cluster/compose/docker-compose.yaml.in similarity index 64% rename from examples/cluster/compose/docker-compose.yaml rename to examples/cluster/compose/docker-compose.yaml.in index 841155f8156..e81e2e44ac4 100644 --- a/examples/cluster/compose/docker-compose.yaml +++ b/examples/cluster/compose/docker-compose.yaml.in @@ -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 @@ -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 @@ -75,7 +85,7 @@ services: logging: <<: *logging volumes: - - ../build/nodes/peer2:/etc/hyperledger/fabric + - ./nodes/peer2:/etc/hyperledger/fabric depends_on: - orderer - peer1 @@ -83,7 +93,6 @@ services: peer3: container_name: peer3 extends: - file: peer-base/peer-base.yaml service: peer-base environment: - CORE_PEER_ID=peer3 @@ -93,7 +102,7 @@ services: logging: <<: *logging volumes: - - ../build/nodes/peer3:/etc/hyperledger/fabric + - ./nodes/peer3:/etc/hyperledger/fabric depends_on: - orderer - peer1 @@ -101,7 +110,6 @@ services: peer4: container_name: peer4 extends: - file: peer-base/peer-base.yaml service: peer-base environment: - CORE_PEER_ID=peer4 @@ -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 diff --git a/examples/cluster/compose/peer-base/peer-base.yaml b/examples/cluster/compose/peer-base/peer-base.yaml deleted file mode 100644 index 6200dc98407..00000000000 --- a/examples/cluster/compose/peer-base/peer-base.yaml +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright IBM Corp. All Rights Reserved. -# -# SPDX-License-Identifier: Apache-2.0 -# - -version: '2' -services: - peer-base: - image: hyperledger/fabric-peer - dns_search: . - environment: - - CORE_PEER_TLS_ENABLED=${TLS_ENABLED} - - CORE_LOGGING_LEVEL=WARNING - - CORE_NEXT=true - - 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 diff --git a/examples/cluster/usage.txt b/examples/cluster/usage.txt index 05d27226da1..5fd21acea1a 100644 --- a/examples/cluster/usage.txt +++ b/examples/cluster/usage.txt @@ -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/