Skip to content

Commit

Permalink
FAB-17243 Add support for Fabric CA for Org3 on the (#91)
Browse files Browse the repository at this point in the history
test network.

Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com>
  • Loading branch information
nikhil550 authored and lehors committed Jan 16, 2020
1 parent ce41ff7 commit b3b5267
Show file tree
Hide file tree
Showing 17 changed files with 939 additions and 230 deletions.
49 changes: 2 additions & 47 deletions test-network/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
## Running the test network

Use the `./network.sh` script to stand up a simple Fabric test network. The
network has two peer peer organizations with one peer each and a single node
raft ordering service. You can also use the script to create channels, and deploy
the fabcar chaincode on those channels. The test network is being introduced in
Fabric v2.0 as the long term replacement for the `first-network` sample.
You can use the `./network.sh` script to stand up a simple Fabric test network. The test network has two peer organizations with one peer each and a single node raft ordering service. You can also use the `./network.sh` script to create channels and deploy the fabcar chaincode. For more information, see [Using the Fabric test network](https://hyperledger-fabric.readthedocs.io/en/latest/test_network.html). The test network is being introduced in Fabric v2.0 as the long term replacement for the `first-network` sample.

Before you can deploy the test network, you need follow the instructions to
[Install the Samples, Binaries and Docker Images](https://hyperledger-fabric.readthedocs.io/en/latest/install.html) in the Hyperledger Fabric documentation. You may experience problems if you run the
sample using a local build.

For more information, see `./network.sh -help`
```
Usage:
network.sh <Mode> [Flags]
<Mode>
- 'up' - bring up fabric orderer and peer nodes. No channel is created
- 'up createChannel' - bring up fabric network with one channel
- 'createChannel' - create and join a channel after the network is created
- 'deployCC' - deploy the fabcar chaincode on the channel
- 'down' - clear the network with docker-compose down
- 'restart' - restart the network
Flags:
-ca <use CAs> - create Certificate Authorities to generate the crypto material
-c <channel name> - channel name to use (defaults to "mychannel")
-s <dbtype> - the database backend to use: goleveldb (default) or couchdb
-r <max retry> - CLI times out after certain number of attempts (defaults to 5)
-d <delay> - delay duration in seconds (defaults to 3)
-l <language> - the programming language of the chaincode to deploy: go (default), javascript, or java
-v <version> - chaincode version. Must be a round number, 1, 2, 3, etc
-i <imagetag> - the tag to be used to launch the network (defaults to "latest")
-verbose - verbose mode
network.sh -h (print this message)
Possible Mode and flags
network.sh up -ca -c -r -d -s -i -verbose
network.sh up createChannel -ca -c -r -d -s -i -verbose
network.sh createChannel -c -r -d -verbose
network.sh deployCC -l -v -r -d -verbose
Taking all defaults:
network.sh up
Examples:
network.sh up createChannel -ca -c mychannel -s couchdb -i 1.4.0
network.sh createChannel -c channelName
network.sh deployCC -l node
```
Before you can deploy the test network, you need to follow the instructions to [Install the Samples, Binaries and Docker Images](https://hyperledger-fabric.readthedocs.io/en/latest/install.html) in the Hyperledger Fabric documentation.
28 changes: 28 additions & 0 deletions test-network/addOrg3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Adding Org3 to the test network

You can use the `addOrg3.sh` script to add another organization to the Fabric test network. The `addOrg3.sh` script generates the Org3 crypto material, creates an Org3 organization definition, and adds Org3 to a channel on the test network.

You first need to run `./network.sh up createChannel` in the `test-network` directory before you can run the `addOrg3.sh` script.

```
./network.sh up createChannel
cd addOrg3
./addOrg3.sh up
```

If you used `network.sh` to create a channel other than the default `mychannel`, you need pass that name to the `addorg3.sh` script.
```
./network.sh up createChannel -c channel1
cd addOrg3
./addOrg3.sh up -c channel1
```

You can also re-run the `addOrg3.sh` script to add Org3 to additional channels.
```
cd ..
./network.sh createChannel -c channel2
cd addOrg3
./addOrg3.sh up -c channel2
```

For more information, use `./addOrg3.sh -h` to see the `addOrg3.sh` help text.
215 changes: 154 additions & 61 deletions test-network/addOrg3/addOrg3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ function printHelp () {
echo " addOrg3.sh up|down|generate [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>]"
echo " addOrg3.sh -h|--help (print this message)"
echo " <mode> - one of 'up', 'down', or 'generate'"
echo " - 'up' - add org3 to the sample network. You need to create a channel first."
echo " - 'down' - clear the network with docker-compose down"
echo " - 'up' - add org3 to the sample network. You need to bring up the test network and create a channel first."
echo " - 'down' - bring down the test network and org3 nodes"
echo " - 'generate' - generate required certificates and org definition"
echo " -c <channel name> - channel name to use (defaults to \"mychannel\")"
echo " -c <channel name> - test network channel name (defaults to \"mychannel\")"
echo " -ca <use CA> - Use a CA to generate the crypto material"
echo " -t <timeout> - CLI timeout duration in seconds (defaults to 10)"
echo " -d <delay> - delay duration in seconds (defaults to 3)"
echo " -f <docker-compose-file> - specify which docker-compose file use (defaults to docker-compose-cli.yaml)"
echo " -s <dbtype> - the database backend to use: goleveldb (default) or couchdb"
echo " -i <imagetag> - the tag to be used to launch the network (defaults to \"latest\")"
echo " -v - verbose mode"
echo " -verbose - verbose mode"
echo
echo "Typically, one would first generate the required certificates and "
echo "genesis block, then bring up the network. e.g.:"
echo
echo " addOrg3.sh generate"
echo " addOrg3.sh up"
echo " addOrg3.sh up -c mychannel -s couchdb"
echo " addOrg3.sh up -l node"
echo " addOrg3.sh down -c mychannel"
echo " addOrg3.sh down"
echo
echo "Taking all defaults:"
echo " addOrg3.sh up"
Expand All @@ -49,27 +49,76 @@ function printHelp () {
# (x509 certs) for the new org. After we run the tool, the certs will
# be put in the organizations folder with org1 and org2

# Generates Org3 certs using cryptogen tool
function generateOrg3 (){
which cryptogen
if [ "$?" -ne 0 ]; then
echo "cryptogen tool not found. exiting"
exit 1
# Create Organziation crypto material using cryptogen or CAs
function generateOrg3() {

# Create crypto material using cryptogen
if [ "$CRYPTO" == "cryptogen" ]; then
which cryptogen
if [ "$?" -ne 0 ]; then
echo "cryptogen tool not found. exiting"
exit 1
fi
echo
echo "##########################################################"
echo "##### Generate certificates using cryptogen tool #########"
echo "##########################################################"
echo

echo "##########################################################"
echo "############ Create Org1 Identities ######################"
echo "##########################################################"

set -x
cryptogen generate --config=org3-crypto.yaml --output="../organizations"
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate certificates..."
exit 1
fi

fi

# Create crypto material using Fabric CAs
if [ "$CRYPTO" == "Certificate Authorities" ]; then

fabric-ca-client version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Fabric CA client not found locally, downloading..."
cd ../..
curl -s -L "https://github.com/hyperledger/fabric-ca/releases/download/v1.4.4/hyperledger-fabric-ca-${OS_ARCH}-1.4.4.tar.gz" | tar xz || rc=$?
if [ -n "$rc" ]; then
echo "==> There was an error downloading the binary file."
echo "fabric-ca-client binary is not available to download"
else
echo "==> Done."
cd test-network/addOrg3/
fi
fi

echo
echo "##########################################################"
echo "##### Generate certificates using Fabric CA's ############"
echo "##########################################################"

IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE_CA_ORG3 up -d 2>&1

. fabric-ca/registerEnroll.sh

sleep 10

echo "##########################################################"
echo "############ Create Org1 Identities ######################"
echo "##########################################################"

createOrg3

fi
echo
echo "###############################################################"
echo "##### Generate Org3 certificates using cryptogen tool #########"
echo "###############################################################"

set -x
cryptogen generate --config=org3-crypto.yaml --output="../organizations"
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate certificates..."
exit 1
fi
echo
echo "Generate CCP files for Org3"
./ccp-generate.sh
}

# Generate channel configuration transaction
Expand All @@ -80,7 +129,7 @@ function generateOrg3Definition() {
exit 1
fi
echo "##########################################################"
echo "######### Generating Org3 config material ###############"
echo "####### Generating Org3 organization definition #########"
echo "##########################################################"
export FABRIC_CFG_PATH=$PWD
set -x
Expand All @@ -94,24 +143,40 @@ function generateOrg3Definition() {
echo
}


function Org3Up () {
# start org3 nodes
if [ "${DATABASE}" == "couchdb" ]; then
IMAGE_TAG=${IMAGETAG} docker-compose -f $COMPOSE_FILE_ORG3 -f $COMPOSE_FILE_COUCH_ORG3 up -d 2>&1
else
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE_ORG3 up -d 2>&1
fi
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start Org3 network"
exit 1
fi
}

# Generate the needed certificates, the genesis block and start the network.
function networkUp () {
function addOrg3 () {

# If the test network is not up, abort
if [ ! -d ../organizations/ordererOrganizations ]; then
echo
echo "ERROR: Please, run ./network.sh up createChannel first."
echo
exit 1
fi

# generate artifacts if they don't exist
if [ ! -d "../organizations/peerOrganizations/org3.example.com" ]; then
generateOrg3
generateOrg3Definition
fi
# start org3 peers
if [ "${DATABASE}" == "couchdb" ]; then
IMAGE_TAG=${IMAGETAG} docker-compose -f $COMPOSE_FILE_ORG3 -f $COMPOSE_FILE_COUCH_ORG3 up -d 2>&1
else
IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE_ORG3 up -d 2>&1
fi
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start Org3 network"
exit 1

CONTAINER_IDS=$(docker ps -a | awk '($2 ~ /fabric-tools/) {print $1}')
if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then
echo "Bringing up network"
Org3Up
fi

# Use the CLI container to create the configuration transaction needed to add
Expand Down Expand Up @@ -143,23 +208,18 @@ function networkDown () {

cd ..
./network.sh down

}


# If the test network is not up, abort
if [ ! -d ../organizations/peerOrganizations ]; then
echo
echo "ERROR: Please, run network.sh first."
echo
exit 1
fi

# Obtain the OS and Architecture string that will be used to select the correct
# native binaries for your platform
OS_ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
# timeout duration - the duration the CLI should wait for a response from
# another container before giving up

# Using crpto vs CA. default is cryptogen
CRYPTO="cryptogen"

CLI_TIMEOUT=10
#default for delay
CLI_DELAY=3
Expand All @@ -169,39 +229,72 @@ CHANNEL_NAME="mychannel"
COMPOSE_FILE_COUCH_ORG3=docker/docker-compose-couch-org3.yaml
# use this as the default docker-compose yaml definition
COMPOSE_FILE_ORG3=docker/docker-compose-org3.yaml
# certificate authorities compose file
COMPOSE_FILE_CA_ORG3=docker/docker-compose-ca-org3.yaml
# default image tag
IMAGETAG="latest"
# database
DATABASE="leveldb"

# Parse commandline args

MODE=$1;
shift
## Parse mode
if [[ $# -lt 1 ]] ; then
printHelp
exit 0
else
MODE=$1
shift
fi

# parse flags

while getopts "h?c:t:d:f:s:l:i:v" opt; do
case "$opt" in
h|\?)
printHelp
exit 0
while [[ $# -ge 1 ]] ; do
key="$1"
case $key in
-h )
printHelp
exit 0
;;
c) CHANNEL_NAME=$OPTARG
-c )
CHANNEL_NAME="$2"
shift
;;
t) CLI_TIMEOUT=$OPTARG
-ca )
CRYPTO="Certificate Authorities"
;;
d) CLI_DELAY=$OPTARG
-t )
CLI_TIMEOUT="$2"
shift
;;
f) COMPOSE_FILE=$OPTARG
-d )
CLI_DELAY="$2"
shift
;;
s) DATABASE=$OPTARG
-s )
DATABASE="$2"
shift
;;
i) IMAGETAG=$OPTARG
-i )
IMAGETAG=$(go env GOARCH)"-""$2"
shift
;;
v) VERBOSE=true
-verbose )
VERBOSE=true
shift
;;
* )
echo
echo "Unknown flag: $key"
echo
printHelp
exit 1
;;
esac
shift
done


# Determine whether starting, stopping, restarting or generating for announce
if [ "$MODE" == "up" ]; then
echo "Add Org3 to channel '${CHANNEL_NAME}' with '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds and using database '${DATABASE}'"
Expand All @@ -217,7 +310,7 @@ fi

#Create the network using docker compose
if [ "${MODE}" == "up" ]; then
networkUp
addOrg3
elif [ "${MODE}" == "down" ]; then ## Clear the network
networkDown
elif [ "${MODE}" == "generate" ]; then ## Generate Artifacts
Expand Down
Loading

0 comments on commit b3b5267

Please sign in to comment.