mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 07:25:10 +00:00
Add in a setEnvOrg script (#487)
Helper script to set environment variables, so make it eaiser to use the peer command from the shell command line Signed-off-by: Matthew B White <whitemat@uk.ibm.com>
This commit is contained in:
parent
38e08da13b
commit
a97c0b0359
2 changed files with 78 additions and 0 deletions
|
|
@ -3,3 +3,22 @@
|
|||
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 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 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.
|
||||
|
||||
## Using the Peer commands
|
||||
The `setOrgEnv.sh` script can be used to setup the environment variables for the ogrganziations, this will will help to be able to use the `peer` commands directly.
|
||||
|
||||
First, ensure that the peer binaries are on your path, and the Fabric Config path is set Assuming that you're in the `test-network` directory.
|
||||
|
||||
```bash
|
||||
export PATH=$PATH:$(realpath ../bin)
|
||||
export FABRIC_CFG_PATH=$(realpath ../config)
|
||||
```
|
||||
|
||||
You can then set up the environment variables for each organization. The `./setOrgEnv.sh` command is designed to be run as follows.
|
||||
|
||||
```bash
|
||||
export $(./setOrgEnv.sh Org2 | xargs)
|
||||
```
|
||||
|
||||
You will now be able to run the `peer` commands in the context of Org2. If a different command prompt you can run the same command with Org1 instead.
|
||||
The `setOrgEnv` script outputs a series of `<name>=<value>` strings. These can then be fed into the export command for your current shell
|
||||
59
test-network/setOrgEnv.sh
Executable file
59
test-network/setOrgEnv.sh
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
|
||||
|
||||
|
||||
# default to using Org1
|
||||
ORG=${1:-Org1}
|
||||
|
||||
# Exit on first error, print all commands.
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Where am I?
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
|
||||
|
||||
ORDERER_CA=${DIR}/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
|
||||
PEER0_ORG1_CA=${DIR}/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
|
||||
PEER0_ORG2_CA=${DIR}/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
||||
PEER0_ORG3_CA=${DIR}/test-network/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
|
||||
|
||||
|
||||
if [[ ${ORG,,} == "org1" || ${ORG,,} == "digibank" ]]; then
|
||||
|
||||
CORE_PEER_LOCALMSPID=Org1MSP
|
||||
CORE_PEER_MSPCONFIGPATH=${DIR}/test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
|
||||
CORE_PEER_ADDRESS=localhost:7051
|
||||
CORE_PEER_TLS_ROOTCERT_FILE=${DIR}/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
|
||||
|
||||
elif [[ ${ORG,,} == "org2" || ${ORG,,} == "magnetocorp" ]]; then
|
||||
|
||||
CORE_PEER_LOCALMSPID=Org2MSP
|
||||
CORE_PEER_MSPCONFIGPATH=${DIR}/test-network/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
|
||||
CORE_PEER_ADDRESS=localhost:9051
|
||||
CORE_PEER_TLS_ROOTCERT_FILE=${DIR}/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
||||
|
||||
else
|
||||
echo "Unknown \"$ORG\", please choose Org1/Digibank or Org2/Magnetocorp"
|
||||
echo "For example to get the environment variables to set upa Org2 shell environment run: ./setOrgEnv.sh Org2"
|
||||
echo
|
||||
echo "This can be automated to set them as well with:"
|
||||
echo
|
||||
echo 'export $(./setOrgEnv.sh Org2 | xargs)'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# output the variables that need to be set
|
||||
echo "CORE_PEER_TLS_ENABLED=true"
|
||||
echo "ORDERER_CA=${ORDERER_CA}"
|
||||
echo "PEER0_ORG1_CA=${PEER0_ORG1_CA}"
|
||||
echo "PEER0_ORG2_CA=${PEER0_ORG2_CA}"
|
||||
echo "PEER0_ORG3_CA=${PEER0_ORG3_CA}"
|
||||
|
||||
echo "CORE_PEER_MSPCONFIGPATH=${CORE_PEER_MSPCONFIGPATH}"
|
||||
echo "CORE_PEER_ADDRESS=${CORE_PEER_ADDRESS}"
|
||||
echo "CORE_PEER_TLS_ROOTCERT_FILE=${CORE_PEER_TLS_ROOTCERT_FILE}"
|
||||
|
||||
echo "CORE_PEER_LOCALMSPID=${CORE_PEER_LOCALMSPID}"
|
||||
Loading…
Reference in a new issue