hyperledger / fabric-samples

Samples for Hyperledger Fabric
https://wiki.hyperledger.org/display/fabric
Apache License 2.0
2.78k stars 3.37k forks source link

test-network-in-a-box #631

Open jkneubuh opened 2 years ago

jkneubuh commented 2 years ago

@mbwhite showed an amazing demonstration / prototype by embedding a "zero-to-blockchain-in-one-command" example with the hlfsupport-in-a-box project. HLF-in-a-box sets up all of the project dependencies, ansible playbooks, and scripting necessary to spin up a network on a remote OCP with a single command.

This Issue / Feature describes an analogous command, but targeting the core Fabric test-network and test-network-k8s projects.

To implement this feature, bundle all of the pre-requisites, scripts, manifests, etc. etc... necessary to spin up a test network, and package everything together in a runnable Docker image. In a kubernetes cluster, the image can just "run" with a kubectl run (or job) in the cluster, inheriting the default service account and kube context. It's not immediately clear how the mechanics will work for the compose-based network, but it certainly would be convenient to run the setup with a single docker run command.

The expected usage is:

kubectl apply \
  -n my-namespace \
  -f https://raw.githubusercontent.com/hyperledger/fabric-samples/main/test-network-k8s/kube/install-test-network-job.yaml

Some really convenient extension ideas:

mbwhite commented 2 years ago

On the compose file route; the mounts of directories make it un-practical to follow the same route. at least not with doing a lot work.

An alternative to this is something more like this script below. I'm trialling for use in the other repos, as way to just get the test-network ready for testing. In this context, the script is run before the tests, and it will setup the docker images, binaries, and the test-network from fabric-samples ONLY. All in a subdirectory (that either is empty or will be created)

#!/bin/bash
# fabric-quickly.sh

set -e -u -o pipefail
ROOTDIR=$(cd "$(dirname "$0")" && pwd)

prefix=fab-test-net
tempdir=$(mktemp -d -t "$prefix.XXXXX") || error_exit "Error creating temporary directory"

DIR=${ROOTDIR}/fabric-install
if [ -d "$DIR" ]
then
    if [ "$(ls -A $DIR)" ]; then
     echo "test-network $DIR is not Empty"
     exit 1
    fi
else
    echo "Directory $DIR not found. Creating..."
    mkdir -p ${DIR}
fi

pushd ${tempdir}
curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh \
    && chmod +x install-fabric.sh \
    && ./install-fabric.sh binary samples
popd

cp -r ${tempdir}/fabric-samples/bin ${DIR}
cp -r ${tempdir}/fabric-samples/config ${DIR}
cp -r ${tempdir}/fabric-samples/test-network ${DIR}

rm -Rf "$tempdir"

the network.sh script would be amenable to use if it was able to be run from any directory, PR #634 has been pushed up for this.

jkneubuh commented 2 years ago

Here's a target:

Effectively, you push a button and Voila! : the test network emerges and is ready for Gateway app development.