зеркало из https://github.com/microsoft/CCF.git
Bash script deploy network (#491)
This commit is contained in:
Родитель
d0bc4ac18e
Коммит
2642177b79
|
@ -3,7 +3,24 @@ Quickstart
|
|||
|
||||
First, you should :ref:`setup a CCF-compatible environment <Environment Setup>`. Then, you will be able to :ref:`build CCF from source and run CCF test suite <Building CCF>`. Note that for rapid prototyping, you can run a `virtual` build of CCF that does not require Intel SGX.
|
||||
|
||||
Once this is done, make sure you get familiar with some of :ref:`CCF concepts`. You will then be able to:
|
||||
Once this is done, you can quickly spin up a CCF network and start :ref:`issuing commands to the deployed application <Issuing Commands>`:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ cd CCF/build
|
||||
$ ../start_test_network.sh libloggingenc.so.signed
|
||||
Setting up Python environment...
|
||||
Python environment successfully setup
|
||||
[2019-10-29 14:47:41.562] Starting 3 CCF nodes...
|
||||
[2019-10-29 14:48:12.138] Started CCF network with the following nodes:
|
||||
[2019-10-29 14:48:12.138] Node [ 0] = 127.177.10.108:37765
|
||||
[2019-10-29 14:48:12.138] Node [ 1] = 127.169.74.37:58343
|
||||
[2019-10-29 14:48:12.138] Node [ 2] = 127.131.108.179:50532
|
||||
[2019-10-29 14:48:12.138] You can now issue business transactions to the libloggingenc application.
|
||||
[2019-10-29 14:48:12.138] See https://microsoft.github.io/CCF/users/issue_commands.html for more information.
|
||||
[2019-10-29 14:48:12.138] Press Ctrl+C to shutdown the network.
|
||||
|
||||
You should also get familiar with some of :ref:`CCF concepts`. You will then be able to:
|
||||
|
||||
1. :ref:`Create a consortium and agree on the constitution <Member Governance>`
|
||||
2. :ref:`Develop a CCF application, based on the example logging application <Example App>`
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
Deploy an Application
|
||||
=====================
|
||||
|
||||
The quickest way to deploy a CCF application is to use the `start_test_network.sh <https://github.com/microsoft/CCF/blob/master/start_test_network.sh>`_ test script, specifying the :ref:`enclave image <Writing CCF Applications>` to run.
|
||||
|
||||
The script creates a new test CCF network composed of 3 nodes running locally. All the governance requests required to open the network to users are automatically issued.
|
||||
|
||||
For example, deploying the ``libloggingenc`` example application:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ cd CCF/build
|
||||
$ ../start_test_network.sh libloggingenc.so.signed
|
||||
Setting up Python environment...
|
||||
Python environment successfully setup
|
||||
[2019-10-29 14:47:41.562] Starting 3 CCF nodes...
|
||||
[2019-10-29 14:48:12.138] Started CCF network with the following nodes:
|
||||
[2019-10-29 14:48:12.138] Node [ 0] = 127.177.10.108:37765
|
||||
[2019-10-29 14:48:12.138] Node [ 1] = 127.169.74.37:58343
|
||||
[2019-10-29 14:48:12.138] Node [ 2] = 127.131.108.179:50532
|
||||
[2019-10-29 14:48:12.138] You can now issue business transactions to the libloggingenc application.
|
||||
[2019-10-29 14:48:12.138] See https://microsoft.github.io/CCF/users/issue_commands.html for more information.
|
||||
[2019-10-29 14:48:12.138] Press Ctrl+C to shutdown the network.
|
||||
|
||||
.. note:: To use CCF `virtual` mode, the same command can be run with ``TEST_ENCLAVE=virtual`` set as environment variable and the virtual version of the enclave application passed to the script. For example ``$ TEST_ENCLAVE=virtual ../start_test_network.sh libloggingenc.virtual.so``.
|
||||
|
||||
The log files (``out`` and ``err``) and ledger (``<node_id>.ledger``) for each CCF node can be found under ``CCF/build/workspace/test_network_<node_id>``.
|
||||
|
||||
.. note:: The first time the command is run, a Python virtual environment will be created. This may take a few seconds. It will not be run the next time the ``start_test_network.sh`` script is started.
|
||||
|
||||
In a different terminal, using the local IP address and port of the CCF nodes displayed by the command (e.g. ``127.177.10.108:37765`` for node ``0``), it is then possible for users to :ref:`issue business requests <Issuing Commands>`.
|
||||
|
|
@ -11,12 +11,11 @@ To generate the certificate and private key of trusted users should be generated
|
|||
|
||||
Before issuing business transactions to CCF, the certificates of trusted users need to be voted in by the consortium of members (see :ref:`Adding Users`).
|
||||
|
||||
Clients communicate with CCF using framed :term:`JSON-RPC` over :term:`TLS`.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents:
|
||||
|
||||
deploy_app
|
||||
issue_commands
|
||||
client
|
||||
rpc_api
|
|
@ -1,6 +1,8 @@
|
|||
Issuing Commands
|
||||
================
|
||||
|
||||
Clients communicate with CCF using framed :term:`JSON-RPC` over :term:`TLS`.
|
||||
|
||||
Users can issue business transactions to CCF using the ``client`` command-line utility built with CCF. For example, to record a message at a specific id with the :ref:`Example App`:
|
||||
|
||||
.. code-block:: bash
|
||||
|
@ -17,7 +19,7 @@ Users can issue business transactions to CCF using the ``client`` command-line u
|
|||
}
|
||||
}
|
||||
|
||||
$ client --pretty-print --rpc-address node_rpc_ip:node_rpc_port --ca networkcert.pem userrpc --req @request.json user_cert.pem --pk user_privk.pem
|
||||
$ client --pretty-print --rpc-address node_rpc_ip:node_rpc_port --ca networkcert.pem userrpc --req @request.json --cert user_cert.pem --pk user_privk.pem
|
||||
Sending RPC to node_rpc_ip:node_rpc_port
|
||||
Doing user RPC:
|
||||
{
|
||||
|
@ -57,7 +59,7 @@ To guarantee that their request is successfully committed to the ledger, a user
|
|||
}
|
||||
}
|
||||
|
||||
$ client --pretty-print --rpc-address node_rpc_ip:node_rpc_port --ca networkcert.pem userrpc --req @get_commit.json user_cert.pem --pk user_privk.pem
|
||||
$ client --pretty-print --rpc-address node_rpc_ip:node_rpc_port --ca networkcert.pem userrpc --req @get_commit.json --cert user_cert.pem --pk user_privk.pem
|
||||
Sending RPC to node_rpc_ip:node_rpc_port
|
||||
Doing user RPC:
|
||||
{
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the Apache 2.0 License.
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "The application enclave file should be specified (e.g. libloggingenc)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Setting up Python environment..."
|
||||
if [ ! -f "env/bin/activate" ]
|
||||
then
|
||||
python3.7 -m venv env
|
||||
fi
|
||||
source env/bin/activate
|
||||
pip install -q -U -r ../tests/requirements.txt
|
||||
echo "Python environment successfully setup"
|
||||
|
||||
python ../tests/start_network.py --package "$1" --label test_network
|
|
@ -20,10 +20,19 @@ def mk_new(name, contents):
|
|||
|
||||
|
||||
def build_lib_path(lib_name, enclave_type="debug"):
|
||||
if enclave_type == "virtual":
|
||||
return "./{}.virtual.so".format(lib_name)
|
||||
VIRTUAL_EXT = ".virtual.so"
|
||||
SIGNED_EXT = ".so.signed"
|
||||
if os.path.isfile(lib_name):
|
||||
if enclave_type == "virtual" and VIRTUAL_EXT not in lib_name:
|
||||
raise ValueError(f"Virtual mode requires {VIRTUAL_EXT} enclave image")
|
||||
elif enclave_type == "debug" and SIGNED_EXT not in lib_name:
|
||||
raise ValueError(f"Real enclave requires {SIGNED_EXT} enclave image")
|
||||
return f"./{lib_name}"
|
||||
else:
|
||||
return "./{}.so.signed".format(lib_name)
|
||||
if enclave_type == "virtual":
|
||||
return f"./{lib_name}{VIRTUAL_EXT}"
|
||||
else:
|
||||
return f"./{lib_name}{SIGNED_EXT}"
|
||||
|
||||
|
||||
def build_bin_path(bin_name, enclave_type=""):
|
||||
|
|
|
@ -510,8 +510,6 @@ class CCFRemote(object):
|
|||
os.path.basename(ledger_file) if ledger_file else f"{local_node_id}.ledger"
|
||||
)
|
||||
|
||||
cmd = [self.BIN, f"--enclave-file={lib_path}"]
|
||||
|
||||
exe_files = [self.BIN, lib_path] + self.DEPS
|
||||
data_files = ([self.ledger_file] if self.ledger_file else []) + (
|
||||
[sealed_secrets] if sealed_secrets else []
|
||||
|
|
|
@ -4,30 +4,56 @@ import e2e_args
|
|||
import infra.ccf
|
||||
import infra.proc
|
||||
import time
|
||||
import sys
|
||||
|
||||
from loguru import logger as LOG
|
||||
|
||||
|
||||
def run(args):
|
||||
hosts = args.nodes or ["localhost", "localhost"]
|
||||
hosts = args.node or ["localhost"] * 3
|
||||
|
||||
if not args.verbose:
|
||||
LOG.remove()
|
||||
LOG.add(
|
||||
sys.stdout,
|
||||
format="<green>[{time:YYYY-MM-DD HH:mm:ss.SSS}]</green> {message}",
|
||||
)
|
||||
LOG.disable("infra")
|
||||
|
||||
LOG.info("Starting {} CCF nodes...".format(len(hosts)))
|
||||
if args.enclave_type == "virtual":
|
||||
LOG.warning("Virtual mode enabled")
|
||||
|
||||
with infra.ccf.network(hosts, args.build_dir, args.debug_nodes) as network:
|
||||
primary, backups = network.start_and_join(args)
|
||||
|
||||
LOG.info("Network started")
|
||||
LOG.info("Primary node is at {}:{}".format(primary.host, primary.rpc_port))
|
||||
LOG.info("Started CCF network with the following nodes:")
|
||||
LOG.info(
|
||||
" Node [{:2d}] = {}:{}".format(
|
||||
primary.node_id, primary.pubhost, primary.rpc_port
|
||||
)
|
||||
)
|
||||
for b in backups:
|
||||
LOG.info(" Node [{:2d}] = {}:{}".format(b.node_id, b.pubhost, b.rpc_port))
|
||||
|
||||
LOG.info("Started network with the following nodes:")
|
||||
LOG.info(" Primary = {}:{}".format(primary.pubhost, primary.rpc_port))
|
||||
for i, f in enumerate(backups):
|
||||
LOG.info(" Backup[{}] = {}:{}".format(i, f.pubhost, f.rpc_port))
|
||||
LOG.info(
|
||||
"You can now issue business transactions to the {} application.".format(
|
||||
args.package
|
||||
)
|
||||
)
|
||||
LOG.info(
|
||||
"See https://microsoft.github.io/CCF/users/issue_commands.html for more information."
|
||||
)
|
||||
LOG.warning("Press Ctrl+C to shutdown the network.")
|
||||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(60)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
LOG.info("Terminating")
|
||||
LOG.info("Stopping all CCF nodes...")
|
||||
|
||||
LOG.info("All CCF nodes stopped.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -35,7 +61,7 @@ if __name__ == "__main__":
|
|||
def add(parser):
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--nodes",
|
||||
"--node",
|
||||
help="List of hostnames[,pub_hostnames:ports]. If empty, two nodes are spawned locally",
|
||||
action="append",
|
||||
)
|
||||
|
@ -45,6 +71,13 @@ if __name__ == "__main__":
|
|||
help="The enclave package to load (e.g., libloggingenc)",
|
||||
required=True,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
help="If set, start up logs are displayed",
|
||||
action="store_true",
|
||||
default=False,
|
||||
)
|
||||
|
||||
args = e2e_args.cli_args(add)
|
||||
run(args)
|
||||
|
|
Загрузка…
Ссылка в новой задаче