-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·114 lines (88 loc) · 4.66 KB
/
setup.sh
File metadata and controls
executable file
·114 lines (88 loc) · 4.66 KB
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
112
113
114
#!/usr/bin/env bash
# Copyright IBM Corp. All Rights Reserved.
# Copyright 2020 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
if [[ -z "${FPC_PATH}" ]]; then
echo "Error: FPC_PATH not set"
exit 1
fi
##############################################################################################
# Get the fabric samples repo and fetch binaries and container images
##############################################################################################
echo "Prepare fabric samples test-network for FPC"
FABRIC_SAMPLES=${FPC_PATH}/samples/deployment/test-network/fabric-samples
if [ ! -d "${FABRIC_SAMPLES}" ]; then
echo "Fabric samples not found! cloning now!"
git clone https://github.com/hyperledger/fabric-samples "${FABRIC_SAMPLES}"
pushd "${FABRIC_SAMPLES}"
git checkout -b "works" 50b69f6
popd
fi
if [ ! -d "${FABRIC_SAMPLES}/bin" ]; then
echo "Error: no fabric binaries found. Let's run 'network.sh prereq'"
pushd "${FABRIC_SAMPLES}/test-network"
./network.sh prereq
popd
fi
##############################################################################################
# Resolve relative paths for docker volumes
##############################################################################################
# Also there is another issue with this approach here. When working completely inside the FPC dev-container,
# the volume mounts won't work. The reason is that the docker daemon provided by the host cannot parse volume paths.
# For instance, ${FPC_PATH} inside dev-container is `/project/src/github.com/hyperledger/fabric-private-chaincode/`.
# The correct path from the docker daemon perspective is something like
# `/Users/marcusbrandenburger/Developer/gocode/src/github.com/hyperledger/fabric-private-chaincode/` (in my case on the mac).
# For this reason we use DOCKERD_FPC_PATH to resolve relative host paths.
if [ -n "${DOCKERD_FPC_PATH+x}" ]; then
echo "Oo we are in docker mode! we need to use the host fpc path"
FPC_PATH_HOST=${DOCKERD_FPC_PATH}
else
FPC_PATH_HOST=${FPC_PATH}
fi
echo "set FPC_PATH_HOST = ${FPC_PATH_HOST}"
FABRIC_SAMPLES_HOST=${FPC_PATH_HOST}/samples/deployment/test-network/fabric-samples
TEST_NETWORK_HOST=${FABRIC_SAMPLES_HOST}/test-network
TEST_NETWORK=${FABRIC_SAMPLES}/test-network
echo "set FABRIC_SAMPLES_HOST = ${FABRIC_SAMPLES_HOST}"
echo "set TEST_NETWORK_HOST = ${TEST_NETWORK_HOST}"
echo "Resolving relative docker volume paths"
# replace "../" with absolute path
find "${TEST_NETWORK}/compose" -maxdepth 1 \( -name '*compose*.yaml' -o -name '*compose*.yml' \) -exec sed -i -E 's+(- )(\.\.)(/)+\1'"${TEST_NETWORK_HOST}"'\3+g' {} \;
# replace "./" with absolute path
find "${TEST_NETWORK}/compose" -mindepth 2 -maxdepth 2 \( -name '*compose*.yaml' -o -name '*compose*.yml' \) -exec sed -i -E 's+(- )(\.)(/)+\1'"${TEST_NETWORK_HOST}/compose"'\3+g' {} \;
##############################################################################################
# setup blockchain explorer
##############################################################################################
echo "Preparing blockchain explorer"
BE_PATH="${FPC_PATH}/samples/deployment/test-network/blockchain-explorer"
BE_PATH_HOST="${FPC_PATH_HOST}/samples/deployment/test-network/blockchain-explorer"
BE_CONFIG=${BE_PATH}/config.json
BE_CONNECTIONS_PROFILE=${BE_PATH}/connection-profile/test-network.json
BE_DOCKER_COMPOSE="${BE_PATH}/docker-compose.yaml"
if [[ -f "${BE_CONFIG}" ]] && [[ -f "${BE_CONNECTIONS_PROFILE}" ]] && [[ -f "${BE_DOCKER_COMPOSE}" ]]; then
echo "Blockchain explorer files already exists"
echo "Any blockchain explorer configuration are going to be overwritten."
read -p "Are you sure? y/n " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo "Skipping blockchain explorer setup"
echo "Setup done!"
exit 0
fi
fi
# create folders
mkdir -p "${BE_PATH}/connection-profile"
# download configuration files
wget -O "${BE_CONFIG}" https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/config.json
wget -O "${BE_CONNECTIONS_PROFILE}" https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/connection-profile/test-network.json
wget -O "${BE_DOCKER_COMPOSE}" https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/docker-compose.yaml
yq '(. | .networks."mynetwork.com" ) |= . + {"external": true}' -i "${BE_DOCKER_COMPOSE}"
cat > "${BE_PATH}/.env" << EOF
EXPLORER_CONFIG_FILE_PATH=${BE_PATH_HOST}/config.json
EXPLORER_PROFILE_DIR_PATH=${BE_PATH_HOST}/connection-profile
FABRIC_CRYPTO_PATH=${TEST_NETWORK_HOST}/organizations
EOF
##############################################################################################
echo "Setup done!"