forked from microsoft/ccf-app-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox.sh
executable file
·111 lines (99 loc) · 3.34 KB
/
sandbox.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache 2.0 License.
set -e
VENV_DIR=${VENV_DIR:-.venv_ccf_sandbox}
PATH_HERE=$(dirname "$(realpath -s "$0")")
CONSTITUTION_DIR="${PATH_HERE}"
VERSION_FILE="${PATH_HERE}"/../share/VERSION_LONG
is_package_specified=false
is_js_bundle_specified=false
PLATFORM_FILE="${PATH_HERE}"/../share/PLATFORM
platform="virtual"
enclave_type="virtual"
extra_args=()
while [ "$1" != "" ]; do
case $1 in
-p|--package)
is_package_specified=true
extra_args+=("$1" "$2")
shift
;;
-p=*|--package=*)
is_package_specified=true
extra_args+=("$1")
;;
--js-app-bundle)
is_js_bundle_specified=true
extra_args+=("$1" "$2")
shift
;;
--js-app-bundle=*)
is_js_bundle_specified=true
extra_args+=("$1")
;;
-c|--constitution-dir)
CONSTITUTION_DIR=$2
# We don't copy this argument to extra_args
shift
;;
*)
extra_args+=("$1")
;;
esac
shift
done
echo "Setting up Python environment..."
if [ ! -f "${VENV_DIR}/bin/activate" ]; then
python3.8 -m venv "${VENV_DIR}"
fi
# shellcheck source=/dev/null
source "${VENV_DIR}"/bin/activate
pip install -U -q pip
if [ -f "${VERSION_FILE}" ]; then
# install tree
BINARY_DIR=${PATH_HERE}
START_NETWORK_SCRIPT="${PATH_HERE}"/start_network.py
VERSION=$(<"${VERSION_FILE}")
VERSION=${VERSION#"ccf-"}
if [ ${is_package_specified} == false ] && [ ${is_js_bundle_specified} == false ]; then
# Only on install tree, default to installed js logging app
echo "No package/app specified. Defaulting to installed JS logging app"
extra_args+=(--package "${PATH_HERE}/../lib/libjs_generic")
extra_args+=(--js-app-bundle "${PATH_HERE}/../samples/logging/js")
fi
if [ -n "${PYTHON_PACKAGE_PATH}" ]; then
# With an install tree, the python package can be specified, e.g. when testing
# an install just before it is released
echo "Using python package: ${PYTHON_PACKAGE_PATH}"
pip install -q -U -e "${PYTHON_PACKAGE_PATH}"
else
# Note: Strip unsafe suffix if it exists
sanitised_version=${VERSION%"+unsafe"}
pip install -q -U ccf=="${sanitised_version}"
fi
pip install -q -U -r "${PATH_HERE}"/requirements.txt
else
# source tree
BINARY_DIR=.
START_NETWORK_SCRIPT="${PATH_HERE}"/../start_network.py
pip install -q -U -e "${PATH_HERE}"/../../python/
pip install -q -U -r "${PATH_HERE}"/../requirements.txt
fi
echo "Python environment successfully setup"
export CURL_CLIENT=ON
export CURL_CLIENT_USE_COSE=ON
exec python "${START_NETWORK_SCRIPT}" \
--binary-dir "${BINARY_DIR}" \
--enclave-type "${enclave_type}" \
--initial-member-count 1 \
--constitution "${CONSTITUTION_DIR}"/actions.js \
--constitution "${CONSTITUTION_DIR}"/validate.js \
--constitution "${CONSTITUTION_DIR}"/resolve.js \
--constitution "${CONSTITUTION_DIR}"/apply.js \
--ledger-chunk-bytes 5000000 \
--snapshot-tx-interval 10000 \
--initial-node-cert-validity-days 90 \
--initial-service-cert-validity-days 90 \
--label sandbox \
"${extra_args[@]}"