Decouple fabric tools image from fabric sample (#1186)

* Decouple fabric tools image from fabric sample
* update with review comments

Signed-off-by: Sam Yuan <yy19902439@126.com>
This commit is contained in:
Sam Yuan 2024-04-06 18:07:18 +08:00 committed by GitHub
parent 66c9992bf3
commit ebbc419933
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 56 additions and 90 deletions

View file

@ -81,8 +81,6 @@ context PEER_IMAGE ghcr.io/hyperledger-labs/fabric-builder-k8s/k8
context PEER_IMAGE_LABEL 0.11.0 # When using k8s-fabric-peer in Fabric v2.5+, 0.11.0+ should be specified context PEER_IMAGE_LABEL 0.11.0 # When using k8s-fabric-peer in Fabric v2.5+, 0.11.0+ should be specified
context ORDERER_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-orderer context ORDERER_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-orderer
context ORDERER_IMAGE_LABEL ${FABRIC_VERSION} context ORDERER_IMAGE_LABEL ${FABRIC_VERSION}
context TOOLS_IMAGE ${FABRIC_CONTAINER_REGISTRY}/fabric-tools
context TOOLS_IMAGE_LABEL ${FABRIC_VERSION}
context OPERATOR_IMAGE ghcr.io/hyperledger-labs/fabric-operator context OPERATOR_IMAGE ghcr.io/hyperledger-labs/fabric-operator
context OPERATOR_IMAGE_LABEL 1.0.4 context OPERATOR_IMAGE_LABEL 1.0.4
context INIT_IMAGE registry.access.redhat.com/ubi8/ubi-minimal context INIT_IMAGE registry.access.redhat.com/ubi8/ubi-minimal
@ -102,7 +100,6 @@ export FABRIC_DEPLOYER_IMAGE=${DEPLOYER_IMAGE}:${DEPLOYER_IMAGE_LABEL}
export FABRIC_CA_IMAGE=${CA_IMAGE}:${CA_IMAGE_LABEL} export FABRIC_CA_IMAGE=${CA_IMAGE}:${CA_IMAGE_LABEL}
export FABRIC_PEER_IMAGE=${PEER_IMAGE}:${PEER_IMAGE_LABEL} export FABRIC_PEER_IMAGE=${PEER_IMAGE}:${PEER_IMAGE_LABEL}
export FABRIC_ORDERER_IMAGE=${ORDERER_IMAGE}:${ORDERER_IMAGE_LABEL} export FABRIC_ORDERER_IMAGE=${ORDERER_IMAGE}:${ORDERER_IMAGE_LABEL}
export FABRIC_TOOLS_IMAGE=${TOOLS_IMAGE}:${TOOLS_IMAGE_LABEL}
export TEMP_DIR=${PWD}/temp export TEMP_DIR=${PWD}/temp

View file

@ -158,16 +158,17 @@ function addOrg3 () {
infoln "Bringing up Org3 peer" infoln "Bringing up Org3 peer"
Org3Up Org3Up
# Use the CLI container to create the configuration transaction needed to add # Create the configuration transaction needed to add
# Org3 to the network # Org3 to the network
infoln "Generating and submitting config tx to add Org3" infoln "Generating and submitting config tx to add Org3"
${CONTAINER_CLI} exec cli ./scripts/org3-scripts/updateChannelConfig.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE cp ${PWD}/../../config/core.yaml ${PWD}
. ../scripts/org3-scripts/updateChannelConfig.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
fatalln "ERROR !!!! Unable to create config tx" fatalln "ERROR !!!! Unable to create config tx"
fi fi
infoln "Joining Org3 peers to network" infoln "Joining Org3 peers to network"
${CONTAINER_CLI} exec cli ./scripts/org3-scripts/joinChannel.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE . ../scripts/org3-scripts/joinChannel.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
fatalln "ERROR !!!! Unable to join Org3 peers to network" fatalln "ERROR !!!! Unable to join Org3 peers to network"
fi fi

View file

@ -262,26 +262,3 @@ services:
- 9445:9445 - 9445:9445
networks: networks:
- test - test
cli:
container_name: cli
image: hyperledger/fabric-tools:latest
labels:
service: hyperledger-fabric
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- FABRIC_LOGGING_SPEC=INFO
- FABRIC_CFG_PATH=/etc/hyperledger/peercfg
#- FABRIC_LOGGING_SPEC=DEBUG
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- ../organizations:/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations
- ../scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
depends_on:
- peer0.org1.example.com
- peer0.org2.example.com
networks:
- test

View file

@ -135,26 +135,3 @@ services:
- 9445:9445 - 9445:9445
networks: networks:
- test - test
cli:
container_name: cli
image: hyperledger/fabric-tools:latest
labels:
service: hyperledger-fabric
tty: true
stdin_open: true
environment:
- GOPATH=/opt/gopath
- FABRIC_LOGGING_SPEC=INFO
- FABRIC_CFG_PATH=/etc/hyperledger/peercfg
#- FABRIC_LOGGING_SPEC=DEBUG
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash
volumes:
- ../organizations:/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations
- ../scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
depends_on:
- peer0.org1.example.com
- peer0.org2.example.com
networks:
- test

View file

@ -30,9 +30,3 @@ services:
volumes: volumes:
- ./docker/peercfg:/etc/hyperledger/peercfg - ./docker/peercfg:/etc/hyperledger/peercfg
- ${DOCKER_SOCK}:/host/var/run/docker.sock - ${DOCKER_SOCK}:/host/var/run/docker.sock
cli:
container_name: cli
image: hyperledger/fabric-tools:latest
volumes:
- ./docker/peercfg:/etc/hyperledger/peercfg

View file

@ -30,9 +30,3 @@ services:
volumes: volumes:
- ./docker/peercfg:/etc/hyperledger/peercfg - ./docker/peercfg:/etc/hyperledger/peercfg
- ${DOCKER_SOCK}:/host/var/run/docker.sock - ${DOCKER_SOCK}:/host/var/run/docker.sock
cli:
container_name: cli
image: hyperledger/fabric-tools:latest
volumes:
- ./docker/peercfg:/etc/hyperledger/peercfg

View file

@ -70,10 +70,10 @@ function checkPrereqs() {
errorln "https://hyperledger-fabric.readthedocs.io/en/latest/install.html" errorln "https://hyperledger-fabric.readthedocs.io/en/latest/install.html"
exit 1 exit 1
fi fi
# use the fabric tools container to see if the samples and binaries match your # use the fabric peer container to see if the samples and binaries match your
# docker images # docker images
LOCAL_VERSION=$(peer version | sed -ne 's/^ Version: //p') LOCAL_VERSION=$(peer version | sed -ne 's/^ Version: //p')
DOCKER_IMAGE_VERSION=$(${CONTAINER_CLI} run --rm hyperledger/fabric-tools:latest peer version | sed -ne 's/^ Version: //p') DOCKER_IMAGE_VERSION=$(${CONTAINER_CLI} run --rm hyperledger/fabric-peer:latest peer version | sed -ne 's/^ Version: //p')
infoln "LOCAL_VERSION=$LOCAL_VERSION" infoln "LOCAL_VERSION=$LOCAL_VERSION"
infoln "DOCKER_IMAGE_VERSION=$DOCKER_IMAGE_VERSION" infoln "DOCKER_IMAGE_VERSION=$DOCKER_IMAGE_VERSION"

View file

@ -6,7 +6,13 @@
# #
# import utils # import utils
. scripts/envVar.sh # test network home var targets to test network folder
# the reason we use a var here is considering with org3 specific folder
# when invoking this for org3 as test-network/scripts/org3-scripts
# the value is changed from default as $PWD(test-network)
# to .. as relative path to make the import works
test_network_home=${test_network_home:-${PWD}}
. ${test_network_home}/scripts/envVar.sh
# fetchChannelConfig <org> <channel_id> <output_json> # fetchChannelConfig <org> <channel_id> <output_json>
# Writes the current channel config for a given channel to a JSON file # Writes the current channel config for a given channel to a JSON file
@ -20,7 +26,7 @@ fetchChannelConfig() {
infoln "Fetching the most recent configuration block for the channel" infoln "Fetching the most recent configuration block for the channel"
set -x set -x
peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL --tls --cafile "$ORDERER_CA" peer channel fetch config config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL --tls --cafile "$ORDERER_CA"
{ set +x; } 2>/dev/null { set +x; } 2>/dev/null
infoln "Decoding config block to JSON and isolating config to ${OUTPUT}" infoln "Decoding config block to JSON and isolating config to ${OUTPUT}"

View file

@ -2,8 +2,6 @@
# imports # imports
. scripts/envVar.sh . scripts/envVar.sh
. scripts/utils.sh
CHANNEL_NAME="$1" CHANNEL_NAME="$1"
DELAY="$2" DELAY="$2"
@ -94,7 +92,7 @@ joinChannel() {
setAnchorPeer() { setAnchorPeer() {
ORG=$1 ORG=$1
${CONTAINER_CLI} exec cli ./scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME . scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME
} }

View file

@ -8,13 +8,19 @@
# This is a collection of bash functions used by different scripts # This is a collection of bash functions used by different scripts
# imports # imports
. scripts/utils.sh # test network home var targets to test network folder
# the reason we use a var here is considering with org3 specific folder
# when invoking this for org3 as test-network/scripts/org3-scripts
# the value is changed from default as $PWD(test-network)
# to .. as relative path to make the import works
test_network_home=${test_network_home:-${PWD}}
. ${test_network_home}/scripts/utils.sh
export CORE_PEER_TLS_ENABLED=true export CORE_PEER_TLS_ENABLED=true
export ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem export ORDERER_CA=${test_network_home}/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
export PEER0_ORG1_CA=${PWD}/organizations/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem export PEER0_ORG1_CA=${test_network_home}/organizations/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem
export PEER0_ORG2_CA=${PWD}/organizations/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem export PEER0_ORG2_CA=${test_network_home}/organizations/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem
export PEER0_ORG3_CA=${PWD}/organizations/peerOrganizations/org3.example.com/tlsca/tlsca.org3.example.com-cert.pem export PEER0_ORG3_CA=${test_network_home}/organizations/peerOrganizations/org3.example.com/tlsca/tlsca.org3.example.com-cert.pem
# Set environment variables for the peer org # Set environment variables for the peer org
setGlobals() { setGlobals() {
@ -28,17 +34,17 @@ setGlobals() {
if [ $USING_ORG -eq 1 ]; then if [ $USING_ORG -eq 1 ]; then
export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp export CORE_PEER_MSPCONFIGPATH=${test_network_home}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051 export CORE_PEER_ADDRESS=localhost:7051
elif [ $USING_ORG -eq 2 ]; then elif [ $USING_ORG -eq 2 ]; then
export CORE_PEER_LOCALMSPID="Org2MSP" export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG2_CA export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG2_CA
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp export CORE_PEER_MSPCONFIGPATH=${test_network_home}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=localhost:9051 export CORE_PEER_ADDRESS=localhost:9051
elif [ $USING_ORG -eq 3 ]; then elif [ $USING_ORG -eq 3 ]; then
export CORE_PEER_LOCALMSPID="Org3MSP" export CORE_PEER_LOCALMSPID="Org3MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG3_CA export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG3_CA
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp export CORE_PEER_MSPCONFIGPATH=${test_network_home}/organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
export CORE_PEER_ADDRESS=localhost:11051 export CORE_PEER_ADDRESS=localhost:11051
else else
errorln "ORG Unknown" errorln "ORG Unknown"

View file

@ -23,11 +23,18 @@ COUNTER=1
MAX_RETRY=5 MAX_RETRY=5
# import environment variables # import environment variables
. scripts/envVar.sh # test network home var targets to test network folder
# the reason we use a var here is considering with org3 specific folder
# when invoking this for org3 as test-network/scripts/org3-scripts
# the value is changed from default as $PWD(test-network)
# to .. as relative path to make the import works
export test_network_home=..
. ${test_network_home}/scripts/envVar.sh
# joinChannel ORG # joinChannel ORG
joinChannel() { joinChannel() {
ORG=$1 ORG=$1
setGlobals $ORG
local rc=1 local rc=1
local COUNTER=1 local COUNTER=1
## Sometimes Join takes time, hence retry ## Sometimes Join takes time, hence retry
@ -46,7 +53,7 @@ joinChannel() {
setAnchorPeer() { setAnchorPeer() {
ORG=$1 ORG=$1
scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME ${test_network_home}/scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME
} }
setGlobalsCLI 3 setGlobalsCLI 3
@ -54,7 +61,7 @@ BLOCKFILE="${CHANNEL_NAME}.block"
echo "Fetching channel config block from orderer..." echo "Fetching channel config block from orderer..."
set -x set -x
peer channel fetch 0 $BLOCKFILE -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME --tls --cafile "$ORDERER_CA" >&log.txt peer channel fetch 0 $BLOCKFILE -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME --tls --cafile "$ORDERER_CA" >&log.txt
res=$? res=$?
{ set +x; } 2>/dev/null { set +x; } 2>/dev/null
cat log.txt cat log.txt

View file

@ -23,9 +23,13 @@ MAX_RETRY=5
# imports # imports
. scripts/envVar.sh # test network home var targets to test network folder
. scripts/configUpdate.sh # the reason we use a var here is considering with org3 specific folder
. scripts/utils.sh # when invoking this for org3 as test-network/scripts/org3-scripts
# the value is changed from default as $PWD(test-network)
# to .. as relative path to make the import works
export test_network_home=..
. ${test_network_home}/scripts/configUpdate.sh
infoln "Creating config transaction to add org3 to network" infoln "Creating config transaction to add org3 to network"
@ -34,7 +38,7 @@ fetchChannelConfig 1 ${CHANNEL_NAME} config.json
# Modify the configuration to append the new org # Modify the configuration to append the new org
set -x set -x
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ${test_network_home}/organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json
{ set +x; } 2>/dev/null { set +x; } 2>/dev/null
# Compute a config update, based on the differences between config.json and modified_config.json, write it as a transaction to org3_update_in_envelope.pb # Compute a config update, based on the differences between config.json and modified_config.json, write it as a transaction to org3_update_in_envelope.pb
@ -46,7 +50,7 @@ signConfigtxAsPeerOrg 1 org3_update_in_envelope.pb
infoln "Submitting transaction from a different peer (peer0.org2) which also signs it" infoln "Submitting transaction from a different peer (peer0.org2) which also signs it"
setGlobals 2 setGlobals 2
set -x set -x
peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "$ORDERER_CA" peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "$ORDERER_CA"
{ set +x; } 2>/dev/null { set +x; } 2>/dev/null
successln "Config transaction to add org3 to network submitted" successln "Config transaction to add org3 to network submitted"

View file

@ -6,8 +6,13 @@
# #
# import utils # import utils
. scripts/envVar.sh # test network home var targets to test network folder
. scripts/configUpdate.sh # the reason we use a var here is considering with org3 specific folder
# when invoking this for org3 as test-network/scripts/org3-scripts
# the value is changed from default as $PWD(test-network)
# to .. as relative path to make the import works
test_network_home=${test_network_home:-${PWD}}
. ${test_network_home}/scripts/configUpdate.sh
# NOTE: this must be run in a CLI container since it requires jq and configtxlator # NOTE: this must be run in a CLI container since it requires jq and configtxlator
@ -42,7 +47,7 @@ createAnchorPeerUpdate() {
} }
updateAnchorPeer() { updateAnchorPeer() {
peer channel update -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME -f ${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile "$ORDERER_CA" >&log.txt peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME -f ${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile "$ORDERER_CA" >&log.txt
res=$? res=$?
cat log.txt cat log.txt
verifyResult $res "Anchor peer update failed" verifyResult $res "Anchor peer update failed"