Skip to content

Commit

Permalink
Update Fablo version
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikowski committed Sep 16, 2024
1 parent e3ee531 commit ae0e5a9
Showing 1 changed file with 120 additions and 24 deletions.
144 changes: 120 additions & 24 deletions test-network/fablo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

FABLO_VERSION="0.3.0"
FABLO_VERSION="1.2.0"
FABLO_IMAGE_NAME="softwaremill/fablo"
FABLO_IMAGE="$FABLO_IMAGE_NAME:$FABLO_VERSION"

Expand All @@ -28,44 +28,78 @@ getDefaultFabloConfig() {
fi
}

printHelp() {
echo "Fablo -- kick-off and manage your Hyperledger Fabric network
getSnapshotPath() {
path="${1:-'snapshot'}"
if echo "$path" | grep -q "tar.gz$"; then
echo "$path"
else
echo "$path.fablo.tar.gz"
fi
}

Usage:
fablo.sh init [node] [rest]
Creates simple Fablo config in current directory with optional Node.js sample chaincode and REST API.
printSplash() {
darkGray=$'\e[90m'
end=$'\e[0m'
echo ""
echo "┌────── .─. ┌─────. ╷ .────."
echo "│ / \ │ │ │ ╱ ╲ "
echo "├───── / \ ├─────: │ │ │"
echo "│ /───────\ │ │ │ ╲ ╱ "
printf "╵ / \ └─────' └────── '────' %24s\n" "v$FABLO_VERSION"
echo "${darkGray}┌┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┐"
echo "│ https://fablo.io | created at SoftwareMill | backed by Hyperledger Foundation│"
echo "└┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┘${end}"
}

fablo.sh generate [/path/to/fablo-config.json|yaml [/path/to/fablo/target]]
printHelp() {
printSplash
echo "Usage:
fablo init [node] [rest] [dev]
Creates simple Fablo config in current directory with optional Node.js, chaincode and REST API and dev mode.
fablo generate [/path/to/fablo-config.json|yaml [/path/to/fablo/target]]
Generates network configuration files in the given directory. Default config file path is '\$(pwd)/fablo-config.json' or '\$(pwd)/fablo-config.yaml', default (and recommended) directory '\$(pwd)/fablo-target'.
fablo.sh up [/path/to/fablo-config.json|yaml]
fablo up [/path/to/fablo-config.json|yaml]
Starts the Hyperledger Fabric network for given Fablo configuration file, creates channels, installs and instantiates chaincodes. If there is no configuration, it will call 'generate' command for given config file.
fablo.sh <down | start | stop>
fablo <down | start | stop>
Downs, starts or stops the Hyperledger Fabric network for configuration in the current directory. This is similar to down, start and stop commands for Docker Compose.
fablo.sh reboot
fablo reset
Downs and ups the network. Network state is lost, but the configuration is kept intact.
fablo.sh prune
fablo prune
Downs the network and removes all generated files.
fablo.sh recreate [/path/to/fablo-config.json|yaml]
fablo recreate [/path/to/fablo-config.json|yaml]
Prunes and ups the network. Default config file path is '\$(pwd)/fablo-config.json' or '\$(pwd)/fablo-config.yaml'.
fablo.sh chaincode upgrade <chaincode-name> <version>
Upgrades and instantiates chaincode on all relevant peers. Chaincode directory is specified in Fablo config file.
fablo chaincodes install
Installs all chaincodes on relevant peers. Chaincode directory is specified in Fablo config file.
fablo chaincode install <chaincode-name> <version>
Installs chaincode on all relevant peers. Chaincode directory is specified in Fablo config file.
fablo chaincode upgrade <chaincode-name> <version>
Upgrades chaincode on all relevant peers. Chaincode directory is specified in Fablo config file.
fablo.sh channel --help
fablo channel --help
To list available channel query options which can be executed on running network.
fablo.sh use [version]
fablo snapshot <target-snapshot-path>
Creates a snapshot of the network in target path. The snapshot contains all network state, including transactions and identities.
fablo restore <source-snapshot-path>
Restores the network from a snapshot.
fablo use [version]
Updates this Fablo script to specified version. Prints all versions if no version parameter is provided.
fablo.sh <help | --help>
fablo <help | --help>
Prints the manual.
fablo.sh version [--verbose | -v]
fablo version [--verbose | -v]
Prints current Fablo version, with optional details."
}

Expand Down Expand Up @@ -103,18 +137,20 @@ executeOnFabloDocker() {
}

useVersion() {
printSplash
local version="$1"

if [ -n "$version" ]; then
echo "Updating '$0' to version $version..."
set +e
curl -Lf https://github.com/softwaremill/fablo/releases/download/"$version"/fablo.sh -o "$0" && chmod +x "$0"
curl -Lf https://github.com/hyperledger-labs/fablo/releases/download/"$version"/fablo.sh -o "$0" && chmod +x "$0"
else
executeOnFabloDocker "fablo:list-versions"
fi
}

initConfig() {
printSplash
executeOnFabloDocker "fablo:init $1 $2"
cp -R -i "$FABLO_TEMP_DIR/." "$COMMAND_CALL_ROOT/"
}
Expand All @@ -130,6 +166,7 @@ extendConfig() {
}

generateNetworkConfig() {
printSplash
local fablo_config=${1:-$(getDefaultFabloConfig)}
local fablo_target=${2:-$FABLO_TARGET}

Expand All @@ -139,14 +176,19 @@ generateNetworkConfig() {
echo " FABLO_NETWORK_ROOT: $fablo_target"

mkdir -p "$fablo_target"
executeOnFabloDocker "fablo:setup-docker" "$fablo_target" "$fablo_config"
(cd "$fablo_target" && ./hooks/post-generate.sh)
executeOnFabloDocker "fablo:setup-network" "$fablo_target" "$fablo_config"
("$fablo_target/hooks/post-generate.sh")
}

networkPrune() {
if [ -f "$FABLO_TARGET/fabric-docker.sh" ]; then
"$FABLO_TARGET/fabric-docker.sh" down
fi

if [ -f "$FABLO_TARGET/fabric-k8s.sh" ]; then
"$FABLO_TARGET/fabric-k8s.sh" down
fi

echo "Removing $FABLO_TARGET"
rm -rf "$FABLO_TARGET"
}
Expand All @@ -156,7 +198,56 @@ networkUp() {
echo "Network target directory is empty"
generateNetworkConfig "$1"
fi
"$FABLO_TARGET/fabric-docker.sh" up
executeFabloCommand up
}

executeFabloCommand() {
if [ ! -d "$FABLO_TARGET" ]; then
echo "Error: This command needs the network to be generated at '$FABLO_TARGET'! Execute 'generate' or 'up' command."
exit 1
fi

if [ -f "$FABLO_TARGET/fabric-docker.sh" ]; then
echo "Executing Fablo Docker command: $1"
"$FABLO_TARGET/fabric-docker.sh" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
elif [ -f "$FABLO_TARGET/fabric-k8s.sh" ]; then
echo "Executing Fablo Kubernetes command: $1"
"$FABLO_TARGET/fabric-k8s.sh" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
else
echo "Error: Corrupted Fablo target directory ($FABLO_TARGET)"
echo "Cannot execute command $1"
exit 1
fi
}

createSnapshot() {
archive="$(getSnapshotPath "$1")"
echo "Creating network snapshot in '$archive'"

if [ -f "$archive" ]; then
echo "Error: Snapshot file '$archive' already exists!"
exit 1
fi

executeFabloCommand snapshot "$FABLO_TEMP_DIR"
(cd "$FABLO_TEMP_DIR" && tar czf tmp.tar.gz *)
mv "$FABLO_TEMP_DIR/tmp.tar.gz" "$archive"
echo "📦 Created snapshot at '$archive'!"
}

restoreSnapshot() {
archive="$(getSnapshotPath "$1")"
hook_command="$2"
echo "📦 Restoring network from '$archive'"

if [ ! -f "$archive" ]; then
echo "Fablo snapshot file '$archive' does not exist!"
exit 1
fi

tar -xf "$archive" -C "$FABLO_TEMP_DIR"
"$FABLO_TEMP_DIR/fablo-target/fabric-docker.sh" clone-to "$COMMAND_CALL_ROOT" "$hook_command"
echo "📦 Network restored from '$archive'! Execute 'start' command to run it."
}

if [ -z "$COMMAND" ]; then
Expand Down Expand Up @@ -194,7 +285,12 @@ elif [ "$COMMAND" = "recreate" ]; then
networkPrune
networkUp "$2"

elif [ "$COMMAND" = "snapshot" ]; then
createSnapshot "$2"

elif [ "$COMMAND" = "restore" ]; then
restoreSnapshot "$2" "${3:-""}"

else
echo "Executing Fablo docker command: $COMMAND"
"$FABLO_TARGET/fabric-docker.sh" "$COMMAND" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
executeFabloCommand "$COMMAND" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
fi

0 comments on commit ae0e5a9

Please sign in to comment.