This repository has been archived by the owner on Mar 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 728
/
install.sh
executable file
·231 lines (207 loc) · 7.73 KB
/
install.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# REMOVE EXISTING REST SERVER, PLAYGROUND ETC
docker rm -f $(docker ps -a | grep hyperledger/* | awk '{ print $1 }')
docker pull hyperledger/composer-playground:latest
docker pull hyperledger/composer-cli:latest
docker pull hyperledger/composer-rest-server:latest
docker pull hyperledger/letters-of-credit:latest
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# GET AND SETUP FABRIC
rm -rf $DIR/fabric-tools
mkdir $DIR/fabric-tools
chmod 777 $DIR/fabric-tools
cd $DIR/fabric-tools
curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.tar.gz
tar -xvf $DIR/fabric-tools/fabric-dev-servers.tar.gz
$DIR/fabric-tools/startFabric.sh
cd $DIR
# CREATE LOCATION FOR LOCAL CARD STORE
rm -rf $(pwd)/.loc-card-store
mkdir $(pwd)/.loc-card-store
chmod 777 $(pwd)/.loc-card-store
# CREATE CONNECTION PROFILE
rm -fr $(pwd)/loc-stage
mkdir $(pwd)/loc-stage
chmod 777 $(pwd)/loc-stage
echo '{
"name": "hlfv1",
"version": "1.0.0",
"client": {
"organization": "Org1",
"connection": {
"timeout": {
"peer": {
"endorser": "300",
"eventHub": "300",
"eventReg": "300"
},
"orderer": "300"
}
}
},
"orderers": {
"orderer.example.com": {
"url": "grpc://orderer.example.com:7050",
"grpcOptions": {}
}
},
"peers": {
"peer0.org1.example.com": {
"url": "grpc://peer0.org1.example.com:7051",
"eventUrl": "grpc://peer0.org1.example.com:7053",
"grpcOptions": {},
"endorsingPeer": true,
"chaincodeQuery": true,
"ledgerQuery": true,
"eventSource": true
}
},
"channels": {
"composerchannel": {
"orderers": ["orderer.example.com"],
"peers": {
"peer0.org1.example.com": {}
}
}
},
"certificateAuthorities": {
"ca.org1.example.com": {
"url": "http://ca.org1.example.com:7054",
"caName": "ca.org1.example.com"
}
},
"organizations": {
"Org1": {
"mspid": "Org1MSP",
"peers": ["peer0.org1.example.com"],
"certificateAuthorities": ["ca.org1.example.com"]
}
},
"x-type": "hlfv1",
"x-commitTimeout": 100
}' > $(pwd)/loc-stage/connection.json
# CREATE PEER ADMIN CARD AND IMPORT
docker run \
--rm \
--network composer_default \
-v $(pwd)/.loc-card-store:/home/composer/.composer \
-v $(pwd)/loc-stage:/home/composer/loc-stage \
-v $(pwd)/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp:/home/composer/PeerAdmin \
hyperledger/composer-cli:latest \
card create -p loc-stage/connection.json -u PeerAdmin -r PeerAdmin -r ChannelAdmin -f /home/composer/loc-stage/PeerAdmin.card -c PeerAdmin/signcerts/Admin@org1.example.com-cert.pem -k PeerAdmin/keystore/114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457_sk
docker run \
--rm \
--network composer_default \
-v $(pwd)/.loc-card-store:/home/composer/.composer \
-v $(pwd)/loc-stage:/home/composer/loc-stage \
-v $(pwd)/fabric-tools/fabric-scripts/hlfv1/composer/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp:/home/composer/PeerAdmin \
hyperledger/composer-cli:latest \
card import -f /home/composer/loc-stage/PeerAdmin.card
# START PLAYGROUND
docker run \
-d \
--network composer_default \
--name composer \
-v $(pwd)/.loc-card-store:/home/composer/.composer \
-p 8080:8080 \
hyperledger/composer-playground:latest
# WAIT FOR PLAYGROUND TO WAKE UP
sleep 5
# GET THE BNA
ROOT=$DIR/..
cd $ROOT
npm install
cd $DIR
cp $ROOT/node_modules/letters-of-credit-network/dist/letters-of-credit-network.bna letters-of-credit-network.bna
# INSTALL THE BNA
docker run \
--rm \
--network composer_default \
-v $(pwd)/letters-of-credit-network.bna:/home/composer/letters-of-credit-network.bna \
-v $(pwd)/loc-stage:/home/composer/loc-stage \
-v $(pwd)/.loc-card-store:/home/composer/.composer \
hyperledger/composer-cli:latest \
network install -c PeerAdmin@hlfv1 -a letters-of-credit-network.bna
NETWORK_VERSION=$(grep -o '"version": *"[^"]*"' $ROOT/node_modules/letters-of-credit-network/package.json | grep -o '[0-9]\.[0-9]\.[0-9]')
# START THE BNA
docker run \
--rm \
--network composer_default \
-v $(pwd)/letters-of-credit-network.bna:/home/composer/letters-of-credit-network.bna \
-v $(pwd)/loc-stage:/home/composer/loc-stage \
-v $(pwd)/.loc-card-store:/home/composer/.composer \
hyperledger/composer-cli:latest \
network start -n letters-of-credit-network -V $NETWORK_VERSION -c PeerAdmin@hlfv1 -A admin -S adminpw -f /home/composer/loc-stage/bnaadmin.card
docker run \
--rm \
--network composer_default \
-v $(pwd)/loc-stage:/home/composer/loc-stage \
-v $(pwd)/.loc-card-store:/home/composer/.composer \
hyperledger/composer-cli:latest \
card import -f /home/composer/loc-stage/bnaadmin.card
# CREATE THE NEEDED PARTICIPANTS
docker run \
--rm \
--network composer_default \
-v $(pwd)/.loc-card-store:/home/composer/.composer \
hyperledger/composer-cli:latest \
transaction submit -c admin@letters-of-credit-network -d '{"$class": "org.example.loc.CreateDemoParticipants"}'
# SET CORRECT PERMISSIONS
docker exec \
composer \
find /home/composer/.composer -name "*" -exec chmod 777 {} \;
# START THE REST SERVER
docker run \
-d \
--network composer_default \
--name rest \
-v $(pwd)/.loc-card-store:/home/composer/.composer \
-e COMPOSER_CARD=admin@letters-of-credit-network \
-e COMPOSER_NAMESPACES=never \
-p 3000:3000 \
hyperledger/composer-rest-server:latest
#WAIT FOR REST SERVER TO WAKE UP
sleep 10
# START THE LOC APPLICATION
docker run \
-d \
--network composer_default \
--name vda \
-e REACT_APP_REST_SERVER_CONFIG='{"webSocketURL": "ws://localhost:3000", "httpURL": "http://localhost:3000/api"}' \
-p 6001:6001 \
hyperledger/letters-of-credit:latest
#WAIT FOR REACT SERVER TO WAKE UP
sleep 10
# OPEN THE APPLICATION
URLS="http://localhost:6001/tutorial http://localhost:6001/alice http://localhost:6001/matias http://localhost:6001/ella http://localhost:6001/bob http://localhost:8080 http://localhost:3000/explorer/"
case "$(uname)" in
"Darwin") open ${URLS}
;;
"Linux") if [ -n "$BROWSER" ] ; then
$BROWSER http://localhost:6001/tutorial http://localhost:6001/alice http://localhost:6001/matias http://localhost:6001/ella http://localhost:6001/bob http://localhost:8080 http://localhost:3000/explorer/
elif which x-www-browser > /dev/null ; then
nohup x-www-browser ${URLS} < /dev/null > /dev/null 2>&1 &
elif which xdg-open > /dev/null ; then
for URL in ${URLS} ; do
xdg-open ${URL}
done
elif which gnome-open > /dev/null ; then
gnome-open http://localhost:6001/tutorial http://localhost:6001/alice http://localhost:6001/matias http://localhost:6001/ella http://localhost:6001/bob http://localhost:8080 http://localhost:3000/explorer/
else
echo "Could not detect web browser to use - please launch Application and Composer Playground URL using your chosen browser ie: <browser executable name> http://localhost:8080 or set your BROWSER variable to the browser launcher in your PATH"
fi
;;
*) echo "Playground not launched - this OS is currently not supported "
;;
esac