-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix minor bugs, add network.sh script to simplify standing up the network, and add an option to run the network in a single container Note: the updated peerNadmin.sh scripts no longer create or join a channel and now only configure the environment for the relevant peer Signed-off-by: James Taylor <jamest@uk.ibm.com>
- Loading branch information
Showing
19 changed files
with
348 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
channel-artifacts/ | ||
crypto-config/ | ||
data/ | ||
logs/ | ||
*.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
FROM alpine:3.14 AS build | ||
|
||
WORKDIR /build | ||
|
||
ENV HLF_VERSION=2.4.3 | ||
ENV YQ_VERSION=v4.22.1 | ||
ENV YQ_BINARY=yq_linux_amd64 | ||
|
||
RUN apk --no-cache add curl dumb-init | ||
|
||
RUN curl -L --retry 5 --retry-delay 3 "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BINARY}.tar.gz" | tar xz && mv ${YQ_BINARY} /usr/bin/yq | ||
RUN curl -L --retry 5 --retry-delay 3 "https://github.com/hyperledger/fabric/releases/download/v${HLF_VERSION}/hyperledger-fabric-linux-amd64-${HLF_VERSION}.tar.gz" | tar xz | ||
# TODO this is a temporary hack due to missing builder binaries in the 2.4.3 release. See https://github.com/hyperledger/fabric/issues/3286 | ||
RUN curl -L --retry 5 --retry-delay 3 "https://hyperledger-fabric.jfrog.io/artifactory/fabric-binaries/hyperledger-fabric-linux-amd64-2.4-stable.tar.gz" | tar xz bin/ccaas_builder | ||
RUN mv bin/ccaas_builder ccaas_builder | ||
|
||
RUN yq -i 'del(.vm.endpoint) | del(.chaincode.externalBuilders) | .chaincode.externalBuilders[0].name = "ccaas_builder" | .chaincode.externalBuilders[0].path = "/home/nanofab/ccbuilders/ccaas" | .chaincode.externalBuilders[0].propagateEnvironment[0] = "CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG"' config/core.yaml | ||
|
||
COPY chaincode-external/ ./chaincode-external/ | ||
|
||
RUN yq -i '.address = "host.docker.internal:9999"' chaincode-external/connection.json | ||
RUN cd chaincode-external && tar cfz code.tar.gz connection.json && tar cfz external-chaincode.tar.gz code.tar.gz metadata.json | ||
|
||
FROM alpine:3.14 | ||
|
||
ENV FABRIC_CFG_PATH /etc/hyperledger/fabric | ||
|
||
RUN apk --no-cache add libc6-compat | ||
|
||
COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init | ||
COPY --chown=root:root --from=build /build/bin/* /usr/local/bin/ | ||
COPY --chown=root:root --from=build /build/config/* ${FABRIC_CFG_PATH}/ | ||
|
||
RUN addgroup -g 500 nanofab && adduser -u 500 -D -h /home/nanofab -G nanofab nanofab | ||
USER nanofab | ||
WORKDIR /home/nanofab | ||
|
||
RUN mkdir -p ./ccbuilders/ccaas ./network/logs && ln -s /usr/local/bin ./bin && ln -s ${FABRIC_CFG_PATH} ./config | ||
COPY --chown=nanofab:nanofab --from=build /build/ccaas_builder/ /home/nanofab/ccbuilders/ccaas/ | ||
COPY --chown=nanofab:nanofab --from=build /build/chaincode-external/ /home/nanofab/chaincode-external/ | ||
COPY --chown=nanofab:nanofab *.sh *.yaml ./network/ | ||
|
||
WORKDIR /home/nanofab/network | ||
ENTRYPOINT ["/usr/bin/dumb-init", "--"] | ||
CMD ["/home/nanofab/network/network.sh","start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env sh | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
# create channel and add anchor peer | ||
peer channel create -c mychannel -o 127.0.0.1:6050 -f "${PWD}"/channel-artifacts/mychannel.tx --outputBlock "${PWD}"/channel-artifacts/mychannel.block --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt | ||
peer channel update -o 127.0.0.1:6050 -c mychannel -f "${PWD}"/channel-artifacts/Org1MSPanchors.tx --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt | ||
|
||
# join peer to channel | ||
peer channel join -b "${PWD}"/channel-artifacts/mychannel.block |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env sh | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
# join peer to channel | ||
peer channel join -b "${PWD}"/channel-artifacts/mychannel.block |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#!/usr/bin/env sh | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
set -eu | ||
|
||
# Print the usage message | ||
printHelp() { | ||
USAGE="${1:-}" | ||
if [ "$USAGE" = "start" ]; then | ||
echo "Usage: " | ||
echo " network.sh start [Flags]" | ||
echo | ||
echo " Starts the test network" | ||
echo | ||
echo " Flags:" | ||
echo " -d <delay> - CLI delays for a certain number of seconds (defaults to 3)" | ||
echo " -h - Print this message" | ||
elif [ "$USAGE" = "clean" ]; then | ||
echo "Usage: " | ||
echo " network.sh clean [Flags]" | ||
echo | ||
echo " Cleans the test network configuration and data files" | ||
echo | ||
echo " Flags:" | ||
echo " -h - Print this message" | ||
else | ||
echo "Usage: " | ||
echo " network.sh <Mode> [Flags]" | ||
echo " Modes:" | ||
echo " start - Starts the test network" | ||
echo " clean - Cleans the test network configuration and data files" | ||
echo | ||
echo " Flags:" | ||
echo " -h - Print this message" | ||
echo | ||
echo " Examples:" | ||
echo " network.sh start" | ||
fi | ||
} | ||
|
||
networkStart() { | ||
: "${CLI_DELAY:=3}" | ||
|
||
# Clear up all the Fabric processes we start | ||
# shellcheck disable=SC2064 | ||
trap "trap - TERM && kill -- -$$" INT TERM EXIT | ||
|
||
if [ -d "${PWD}"/channel-artifacts ] && [ -d "${PWD}"/crypto-config ]; then | ||
echo "Using existing artifacts..." | ||
CREATE_CHANNEL=false | ||
else | ||
echo "Generating artifacts..." | ||
./generate_artifacts.sh | ||
CREATE_CHANNEL=true | ||
fi | ||
|
||
echo "Creating logs directory..." | ||
mkdir -p "${PWD}"/logs | ||
|
||
sleep $CLI_DELAY | ||
|
||
echo "Starting orderers..." | ||
./orderer1.sh > ./logs/orderer1.log 2>&1 & | ||
./orderer2.sh > ./logs/orderer2.log 2>&1 & | ||
./orderer3.sh > ./logs/orderer3.log 2>&1 & | ||
|
||
sleep $CLI_DELAY | ||
|
||
echo "Starting peers..." | ||
./peer1.sh > ./logs/peer1.log 2>&1 & | ||
./peer2.sh > ./logs/peer2.log 2>&1 & | ||
./peer3.sh > ./logs/peer3.log 2>&1 & | ||
./peer4.sh > ./logs/peer4.log 2>&1 & | ||
|
||
sleep $CLI_DELAY | ||
|
||
if [ "${CREATE_CHANNEL}" = "true" ]; then | ||
echo "Creating channel (peer1)..." | ||
. ./peer1admin.sh && ./create_channel.sh | ||
|
||
echo "Joining channel (peer2)..." | ||
. ./peer2admin.sh && ./join_channel.sh | ||
|
||
echo "Joining channel (peer3)..." | ||
. ./peer3admin.sh && ./join_channel.sh | ||
|
||
echo "Joining channel (peer4)..." | ||
. ./peer4admin.sh && ./join_channel.sh | ||
fi | ||
|
||
echo "Fabric network running, use Ctrl-C to stop" | ||
wait | ||
} | ||
|
||
networkClean() { | ||
echo "Removing directories: channel-artifacts crypto-config data logs" | ||
rm -r "${PWD}"/channel-artifacts || true | ||
rm -r "${PWD}"/crypto-config || true | ||
rm -r "${PWD}"/data || true | ||
rm -r "${PWD}"/logs || true | ||
} | ||
|
||
# Parse commandline args | ||
|
||
## Parse mode | ||
if [ $# -lt 1 ] ; then | ||
printHelp | ||
exit 0 | ||
else | ||
MODE=$1 | ||
shift | ||
fi | ||
|
||
# parse flags | ||
while [ $# -ge 1 ] ; do | ||
key="$1" | ||
case $key in | ||
-d ) | ||
CLI_DELAY="$2" | ||
shift | ||
;; | ||
-h ) | ||
printHelp "$MODE" | ||
exit 0 | ||
;; | ||
* ) | ||
echo "Unknown flag: $key" | ||
printHelp | ||
exit 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ "$MODE" = "start" ]; then | ||
networkStart | ||
elif [ "$MODE" = "clean" ]; then | ||
networkClean | ||
else | ||
printHelp | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.