Skip to content

Commit

Permalink
[FAB-3161] /examples/cluster
Browse files Browse the repository at this point in the history
The purpose of this patch is to provide a tool that will
demonstrate how to assemble a complete cluster of a
v1.0 architecture system, complete with security.

It currently supports docker-compose (via "make compose")
but future plans including adding "make kubernetes", etc.

Usage
===========

$ make
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
- help:                   displays this help message

Example:

        make compose-up TLS=false

Prerequisites:

- Ensure you run "make docker" in both fabric.git and fabric-ca.git
  prior to execution

Notes
===================

The resulting cluster is not production-grade, per se, largely
because of the way the keys are generated all in one place
via cryptogen tool.  However, there are some contexts in
which this might be ok anyway (e.g. loading kubernetes
secrets) and at the very least, its a prescription for the
major steps needed.

You may think of this tool as similar to e2e but with slightly
different goals.  E2E is targetted at easily standing up
a fixed configuration and ensuring chaincode may deploy.  This
is targetted at easily standing up a dynamically generated
crypto configuration in a somewhat realistic manner in a few
different environments.

Change-Id: I16561aa252212ca20645fa5b4a1a89ffd70c1a78
Signed-off-by: Gregory Haskins <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed May 4, 2017
1 parent bc0cf92 commit b4d101b
Show file tree
Hide file tree
Showing 9 changed files with 1,031 additions and 0 deletions.
105 changes: 105 additions & 0 deletions examples/cluster/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
PEERS += $(patsubst %,peer%,$(shell seq 1 4))
NODES += $(PEERS)
NODES += orderer
NODES += cli
NODES += ca

CHANNEL_NAME ?= mychannel

CRYPTOOUTPUT = build/cryptogen
ORDERER_ORG = $(CRYPTOOUTPUT)/ordererOrganizations/orderer.net
PEER_ORG= $(CRYPTOOUTPUT)/peerOrganizations/org1.net

CA_PATH = $(PEER_ORG)/ca
ORDERER_PATH = $(ORDERER_ORG)/orderers
PEER_PATH = $(PEER_ORG)/peers
USERS_PATH = $(PEER_ORG)/users

CHANNEL_TXNS=build/channel.tx build/anchor.tx

mspmap.orderer := $(ORDERER_PATH)/orderer.orderer.net
mspmap.peer1 := $(PEER_PATH)/peer1.org1.net
mspmap.peer2 := $(PEER_PATH)/peer2.org1.net
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

TLS ?= true
export TLS_ENABLED=$(TLS)

CRYPTOGEN=build/bin/cryptogen
CONFIGTXGEN=build/bin/configtxgen

FABRICPKG=github.com/hyperledger/fabric
pkgmap.cryptogen := $(FABRICPKG)/common/tools/cryptogen
pkgmap.configtxgen := $(FABRICPKG)/common/configtx/tool/configtxgen

help:
@cat usage.txt

compose-up: nodes
$(COMPOSE) up -d ca $(PEERS)
$(DRUN) ./configure.sh $(CHANNEL_NAME) "$(CHANNEL_TXNS)" "$(PEERS)" $(TLS)

compose-down:
$(COMPOSE) down
rm -rf build/nodes $(CRYPTOOUTPUT)

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

$(CRYPTOOUTPUT): config/cryptogen.yaml $(CRYPTOGEN)
@mkdir -p ${@D}
$(CRYPTOGEN) generate --config $< --output $@

.PRECIOUS: %.yaml
%.yaml:
@mkdir -p ${@D}
cp config/${@F} $@

%/genesis.block: build/configtx.yaml build/core.yaml $(CONFIGTXGEN)
@mkdir -p ${@D}
FABRIC_CFG_PATH=build $(CONFIGTXGEN) -profile SampleOrg -outputBlock $@

%.tx: build/configtx.yaml build/core.yaml $(CONFIGTXGEN)

%/channel.tx:
@mkdir -p ${@D}
FABRIC_CFG_PATH=build $(CONFIGTXGEN) -profile SampleChannel \
-channelID ${CHANNEL_NAME} \
-outputCreateChannelTx $@

%/anchor.tx:
@mkdir -p ${@D}
FABRIC_CFG_PATH=build $(CONFIGTXGEN) -profile SampleChannel \
-channelID ${CHANNEL_NAME} \
-outputAnchorPeersUpdate $@ \
-asOrg Org1MSP

.PRECIOUS: %/msp
%/msp: $(CRYPTOOUTPUT)
$(eval NODE = ${patsubst build/nodes/%/msp,%,${@}})
@mkdir -p ${@D}
cp -R $(mspmap.${NODE})/* ${@D}

.PRECIOUS: build/bin/%
build/bin/%:
@mkdir -p ${@D}
GOBIN=$(abspath ${@D}) go install $(pkgmap.${@F})

build/nodes/orderer: build/nodes/orderer/orderer.yaml
build/nodes/orderer: build/nodes/orderer/genesis.block
build/nodes/cli: $(CHANNEL_TXNS)

build/nodes/ca:
@mkdir -p $@/tls
cp $(CA_PATH)/*_sk $@/tls/ca.key
cp $(CA_PATH)/*.pem $@/tls/ca.crt

build/nodes/%: build/nodes/%/msp build/nodes/%/configtx.yaml build/nodes/%/core.yaml
@echo "Built $@"

clean: compose-down
rm -rf build
101 changes: 101 additions & 0 deletions examples/cluster/compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
version: '2'

services:

ca:
container_name: ca
image: hyperledger/fabric-ca
dns_search: .
environment:
- FABRIC_CA_SERVER_TLS_ENABLED=${TLS_ENABLED}
- FABRIC_CA_SERVER_TLS_CERTFILE=/etc/hyperledger/fabric-ca-server/tls/ca.crt
- FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server/tls/ca.key
volumes:
- ../build/nodes/ca/tls:/etc/hyperledger/fabric-ca-server/tls

orderer:
container_name: orderer
image: hyperledger/fabric-orderer
dns_search: .
environment:
- ORDERER_GENERAL_TLS_ENABLED=${TLS_ENABLED}
volumes:
- ../build/nodes/orderer:/etc/hyperledger/fabric

peer1:
container_name: peer1
extends:
file: peer-base/peer-base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer1
- CORE_PEER_ADDRESS=peer1:7051
- CORE_PEER_GOSSIP_ENDPOINT=peer1:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.net:7051
volumes:
- ../build/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
- CORE_PEER_ADDRESS=peer2:7051
- CORE_PEER_GOSSIP_ENDPOINT=peer2:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer2.org1.net:7051
volumes:
- ../build/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
- CORE_PEER_ADDRESS=peer3:7051
- CORE_PEER_GOSSIP_ENDPOINT=peer3:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer3.org1.net:7051
volumes:
- ../build/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
- CORE_PEER_ADDRESS=peer4:7051
- CORE_PEER_GOSSIP_ENDPOINT=peer4:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer4.org1.net:7051
volumes:
- ../build/nodes/peer4:/etc/hyperledger/fabric
depends_on:
- orderer
- peer1

cli:
image: hyperledger/fabric-peer
dns_search: .
environment:
- CORE_PEER_TLS_ENABLED=${TLS_ENABLED}
- CORE_NEXT=true
- CORE_LOGGING_LEVEL=DEBUG
volumes:
- ../build/nodes/cli:/etc/hyperledger/fabric
- ..:/cli
working_dir: /cli
depends_on:
- orderer
- peer1
14 changes: 14 additions & 0 deletions examples/cluster/compose/peer-base/peer-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '2'
services:
peer-base:
image: hyperledger/fabric-peer
dns_search: .
environment:
- CORE_PEER_TLS_ENABLED=${TLS_ENABLED}
- CORE_LOGGING_LEVEL=DEBUG
- CORE_NEXT=true
- CORE_PEER_ENDORSER_ENABLED=true
- CORE_PEER_GOSSIP_BOOTSTRAP=peer1:7051
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: peer node start --peer-defaultchain=false
158 changes: 158 additions & 0 deletions examples/cluster/config/configtx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
---
################################################################################
#
# Profile
#
# - Different configuration profiles may be encoded here to be specified
# as parameters to the configtxgen tool
#
################################################################################
Profiles:

SampleOrg:
Orderer:
<<: *OrdererDefaults
Organizations:
- *OrdererOrg
Application:
<<: *ApplicationDefaults
Organizations:
- *Org1
Consortiums:
SampleConsortium:
Organizations:
- *OrdererOrg
- *Org1

SampleChannel:
Consortium: SampleConsortium
Application:
Organizations:
- *Org1

################################################################################
#
# Section: Organizations
#
# - This section defines the different organizational identities which will
# be referenced later in the configuration.
#
################################################################################
Organizations:

# SampleOrg defines an MSP using the sampleconfig. It should never be used
# in production but may be used as a template for other definitions
- &OrdererOrg
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: OrdererOrg

# ID to load the MSP definition as
ID: OrdererMSP

# MSPDir is the filesystem path which contains the MSP configuration
MSPDir: cryptogen/ordererOrganizations/orderer.net/msp

AdminPrincipal: Role.ADMIN

# BCCSP (Blockchain crypto provider): Select which crypto implementation or
# library to use
BCCSP:
Default: SW
SW:
Hash: SHA2
Security: 256
# Location of Key Store. If this is unset, a location will
# be chosen using 'MSPDir'/keystore
FileKeyStore:
KeyStore:

- &Org1
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: Org1MSP

# ID to load the MSP definition as
ID: Org1MSP

MSPDir: cryptogen/peerOrganizations/org1.net/msp

AdminPrincipal: Role.ADMIN

# BCCSP (Blockchain crypto provider): Select which crypto implementation or
# library to use
BCCSP:
Default: SW
SW:
Hash: SHA2
Security: 256
# Location of Key Store. If this is unset, a location will
# be chosen using 'MSPDir'/keystore
FileKeyStore:
KeyStore:

AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: peer1
Port: 7051

################################################################################
#
# SECTION: Orderer
#
# - This section defines the values to encode into a config transaction or
# genesis block for orderer related parameters
#
################################################################################
Orderer: &OrdererDefaults

# Orderer Type: The orderer implementation to start
# Available types are "solo" and "kafka"
OrdererType: solo

Addresses:
- orderer:7050

# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 2s

# Batch Size: Controls the number of messages batched into a block
BatchSize:

# Max Message Count: The maximum number of messages to permit in a batch
MaxMessageCount: 10

# Absolute Max Bytes: The absolute maximum number of bytes allowed for
# the serialized messages in a batch.
AbsoluteMaxBytes: 99 MB

# Preferred Max Bytes: The preferred maximum number of bytes allowed for
# the serialized messages in a batch. A message larger than the preferred
# max bytes will result in a batch larger than preferred max bytes.
PreferredMaxBytes: 512 KB

Kafka:
# Brokers: A list of Kafka brokers to which the orderer connects
# NOTE: Use IP:port notation
Brokers:
- 127.0.0.1:9092

# Organizations is the list of orgs which are defined as participants on
# the orderer side of the network
Organizations:

################################################################################
#
# SECTION: Application
#
# - This section defines the values to encode into a config transaction or
# genesis block for application related parameters
#
################################################################################
Application: &ApplicationDefaults

# Organizations is the list of orgs which are defined as participants on
# the application side of the network
Organizations:
Loading

0 comments on commit b4d101b

Please sign in to comment.