0

Could you please help me to deploy two fabric network on single machine so that it will run two different applications. when I create new application it will clear all data of other application(fabric network) from couchdb.

How can we separately store data for two or more fabric network in couchdb

1 Answers1

0

1. Analyze the convector first.

npm run env:restart
https://github.com/hyperledger-labs/convector

// hyperledger-labs/convector/package.json
    "env:restart": "hurl new -p $PWD/.convector-dev-env",

2. What does the hurl new command do?

https://github.com/worldsibu/hurley

  • Hurley is the development environment toolset for Enterprise Blockchain projects. It supports Hyperledger Fabric and is being ported to support other chain technologies.
hurl new
    [-n --network <path>] # Path to the network definition file
    [-o --organizations <amount-of-organizations>]
    [-u --users <users-per-organization>]
    [-c --channels <amount-of-channels>]
    [-p --path <path-to-install-the-network>]
    [-i --inside] # Whether or not the `hurl` command will runs inside the same Docker network where the blockchain was provisioned
    [--skip-cleanup] Skips cleaning up the <path>/data folder

It is a command that creates network artifacts of the fabric through the hurl command and executes them. If you want to build multiple fabric networks during this process, of course, you need to work to do this independently.

3. Check if the two networks are up.

  • Analyzing hurl is as follows.

  • First, according to the input parameter, createNetwork is called, which calls the init function by the constructor of the cli class.

  • The init function creates new configurations and starts up the network.

  • At this time, new configurations are created based on a predefined template, and you look at the docker-compose side of the templates.

  • The container names of docker-compose are all static and the peer's ports are already bound and distributed.

  • In other words, it has been developed in a structure in which collision can only occur and two networks cannot be launched.

  • To solve this, hurl must be changed or a new blockchain network must be artificially built.

The next best thing is the options below.

The --skip-cleanup option is a parameter that does not delete data.

hurl new -p $PWD/.test-env-1 --skip-cleanup
hurl new -p $PWD/.test-env-2 --skip-cleanup

-> remains two blockchain configurations
-> there are only artifacts for operation, but only one of the actual networks is up.

4. Modify all conflicting items in docker-compose.yaml

  1. docker networks
  2. container name
  3. host port number
# clean network
docker stop $(docker ps -a | awk '$2~/hyperledger/ {print $1}') 
docker rm -f $(docker ps -a | awk '$2~/hyperledger/ {print $1}') $(docker ps -a | awk '{ print $1,$2 }' | grep dev-peer | awk '{print $1 }') || true
docker rmi -f $(docker images | grep dev-peer | awk '{print $3}') || true
# in $PWD/.test-env-1, all files
# (docker-compose, crypto-config, configtx, network-profiles ...)
hurley_dev_net -> hurley_dev_net-1
*hurley.lab -> *hurley.lab-1

# in $PWD/.test-env-2, all files
# (docker-compose, crypto-config, configtx, network-profiles ...)
hurley_dev_net -> hurley_dev_net-2
*hurley.lab -> *hurley.lab-2

# in $PWD/.test-env-2, docker-compose.yaml
host ports -> +1000
ex1) 7050:7050 -> 8050:7050
ex2) 7051:7051 -> 8051:8051

4. Generate new artifacts

cd $PWD/.test-env-1 && \
chmod +x generator.sh && \
./generator.sh
cd $PWD/.test-env-2 && \
chmod +x generator.sh && \
./generator.sh

5. Network up

# change shell script
vi $PWD/.test-env-1/restart.sh
vi $PWD/.test-env-2/restart.sh

# delete below lines
`
ITEMS=$(docker ps -a | awk '$2~/hyperledger/ {print $1}') 

if [ ! -z "$ITEMS" ]; then
    docker stop $(docker ps -a | awk '$2~/hyperledger/ {print $1}') 
    docker rm -f $(docker ps -a | awk '$2~/hyperledger/ {print $1}') $(docker ps -a | awk '{ print $1,$2 }' | grep dev-peer | awk '{print $1 }') || true
    docker rmi -f $(docker images | grep dev-peer | awk '{print $3}') || true
fi
`
# first network up
cd $PWD/.test-env-1 && \
chmod +x restart.sh && \
./restart.sh
# second network up
cd $PWD/.test-env-2 && \
chmod +x restart.sh && \
./restart.sh

6. Modify commands in convector

  • The main thing is, you need to modify the commands so that the network issuing convector's commands changes according to the path of the blockchain network's configuration.

for example

// origin
"cc:install": "f() { hurl install $1 node --debug -P ./chaincode-$1 -p $PWD/.convector-dev-env; }; f"

// after
"cc:install-test-1": "f() { hurl install $1 node --debug -P ./chaincode-$1 -p $PWD/.test-env-1; }; f"

"cc:install-test-2": "f() { hurl install $1 node --debug -P ./chaincode-$1 -p $PWD/.test-env-2; }; f"

+ Since convector and hurley codes are tailored to a single network, it is correct to use a tool other than the above tool if you want to launch multiple networks.

+ Also, it is strange to launch a multi fabric network on a single host. Rather, think about how to split the channels.

myeongkil kim
  • 2,020
  • 4
  • 12
  • 19