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.in
executable file
·253 lines (222 loc) · 8.1 KB
/
install.sh.in
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
ME=`basename "$0"`
if [ "${ME}" = "install-hlfv1-{{ENV}}.sh" ]; then
echo "Please re-run as > cat install-hlfv1-{{ENV}}.sh | bash"
exit 1
fi
(cat > composer.sh; chmod +x composer.sh; exec bash composer.sh)
#!/bin/bash
set -ev
# Docker stop function
function stop()
{
P1=$(docker ps -q)
if [ "${P1}" != "" ]; then
echo "Killing all running containers" &2> /dev/null
docker kill ${P1}
fi
P2=$(docker ps -aq)
if [ "${P2}" != "" ]; then
echo "Removing all containers" &2> /dev/null
docker rm ${P2} -f
fi
}
if [ "$1" == "stop" ]; then
echo "Stopping all Docker containers" >&2
stop
exit 0
fi
# Get the current directory.
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Get the full path to this script.
SOURCE="${DIR}/composer.sh"
# Create a work directory for extracting files into.
WORKDIR="$(pwd)/composer-data-{{ENV}}"
rm -rf "${WORKDIR}" && mkdir -p "${WORKDIR}"
cd "${WORKDIR}"
# Find the PAYLOAD: marker in this script.
PAYLOAD_LINE=$(grep -a -n '^PAYLOAD:$' "${SOURCE}" | cut -d ':' -f 1)
echo PAYLOAD_LINE=${PAYLOAD_LINE}
# Find and extract the payload in this script.
PAYLOAD_START=$((PAYLOAD_LINE + 1))
echo PAYLOAD_START=${PAYLOAD_START}
tail -n +${PAYLOAD_START} "${SOURCE}" | tar -xzf -
# Ensure sensible permissions on the extracted files.
find . -type d | xargs chmod a+rx
find . -type f | xargs chmod a+r
# Pull the latest versions of all the Docker images.
docker pull hyperledger/composer-playground:{{ENV}}
docker pull hyperledger/composer-cli:{{ENV}}
docker pull hyperledger/composer-rest-server:{{ENV}}
docker pull hyperledger/vehicle-lifecycle-vda:{{ENV}}
docker pull hyperledger/vehicle-lifecycle-manufacturing:{{ENV}}
docker pull hyperledger/vehicle-lifecycle-car-builder:{{ENV}}
docker pull nodered/node-red-docker
# stop all the docker containers
stop
# run the fabric-dev-scripts to get a running fabric
./fabric-dev-servers/downloadFabric.sh
./fabric-dev-servers/startFabric.sh
# Create the environment variables and file with the connection profile in.
read -d '' COMPOSER_CONNECTION_PROFILE << EOF || true
{
"name": "hlfv1",
"description": "Hyperledger Fabric v1.0",
"type": "hlfv1",
"keyValStore": "/home/composer/.composer-credentials",
"timeout": 300,
"orderers": [
{
"url": "grpc://orderer.example.com:7050"
}
],
"channel": "composerchannel",
"mspID": "Org1MSP",
"ca": {"url": "http://ca.org1.example.com:7054", "name": "ca.org1.example.com"},
"peers": [
{
"requestURL": "grpc://peer0.org1.example.com:7051",
"eventURL": "grpc://peer0.org1.example.com:7053"
}
]
}
EOF
read -d '' COMPOSER_CONFIG << EOF || true
{
"defaultConnectionProfile": "hlfv1",
"connectionProfiles": {
"hlfv1": ${COMPOSER_CONNECTION_PROFILE}
},
"credentials": {
"hlfv1": {
"PeerAdmin": "NOTUSED",
"admin": "adminpw"
}
}
}
EOF
mkdir -p .composer-connection-profiles/hlfv1
echo ${COMPOSER_CONNECTION_PROFILE} > .composer-connection-profiles/hlfv1/connection.json
# Copy the credentials in.
cp -r fabric-dev-servers/fabric-scripts/hlfv1/composer/creds .composer-credentials
# Start the playground.
docker run \
-d \
--network composer_default \
--name composer \
-v $(pwd)/.composer-connection-profiles:/home/composer/.composer-connection-profiles \
-v $(pwd)/.composer-credentials:/home/composer/.composer-credentials \
-e COMPOSER_CONFIG="${COMPOSER_CONFIG}" \
-p 8080:8080 \
hyperledger/composer-playground:{{ENV}}
# Doctor the permissions on the files so Docker can pointlessly overwrite them.
chmod a+rwx .composer-connection-profiles .composer-connection-profiles/hlfv1 .composer-credentials
chmod a+rw .composer-connection-profiles/hlfv1/connection.json
chmod a+rw .composer-credentials/*
# Deploy the business network archive.
docker run \
--rm \
--network composer_default \
-v $(pwd)/vehicle-lifecycle-network.bna:/home/composer/vehicle-lifecycle-network.bna \
-v $(pwd)/.composer-connection-profiles:/home/composer/.composer-connection-profiles \
-v $(pwd)/.composer-credentials:/home/composer/.composer-credentials \
hyperledger/composer-cli:{{ENV}} \
composer network deploy -p hlfv1 -a vehicle-lifecycle-network.bna -i PeerAdmin -s whatever
# Submit the setup transaction.
docker run \
--rm \
--network composer_default \
-v $(pwd)/.composer-connection-profiles:/home/composer/.composer-connection-profiles \
-v $(pwd)/.composer-credentials:/home/composer/.composer-credentials \
hyperledger/composer-cli:{{ENV}} \
composer transaction submit -p hlfv1 -n org-acme-biznet -i admin -s adminpw -d '{"$class": "org.acme.vehicle.lifecycle.SetupDemo"}'
# Start the REST server.
docker run \
-d \
--network composer_default \
--name rest \
-v $(pwd)/.composer-connection-profiles:/home/composer/.composer-connection-profiles \
-v $(pwd)/.composer-credentials:/home/composer/.composer-credentials \
-e COMPOSER_CONNECTION_PROFILE=hlfv1 \
-e COMPOSER_BUSINESS_NETWORK=org-acme-biznet \
-e COMPOSER_ENROLLMENT_ID=admin \
-e COMPOSER_ENROLLMENT_SECRET=adminpw \
-e COMPOSER_NAMESPACES=required \
-p 3000:3000 \
hyperledger/composer-rest-server:{{ENV}}
# Wait for the REST server to start and initialize.
sleep 10
# Start Node-RED.
docker run \
-d \
--network composer_default \
--name node-red \
-v $(pwd)/.composer-connection-profiles:/usr/src/node-red/.composer-connection-profiles \
-v $(pwd)/.composer-credentials:/usr/src/node-red/.composer-credentials \
-v $(pwd)/.composer-credentials:/home/composer/.composer-credentials \
-e COMPOSER_BASE_URL=http://rest:3000 \
-v $(pwd)/flows.json:/data/flows.json \
-p 1880:1880 \
nodered/node-red-docker
# Install custom nodes
docker exec \
-e NPM_CONFIG_LOGLEVEL=warn \
node-red \
bash -c "cd /data && npm install node-red-contrib-composer@{{ENV}}"
docker restart node-red
# Wait for Node-RED to start and initialize.
sleep 10
# Start the VDA application.
docker run \
-d \
--network composer_default \
--name vda \
-e COMPOSER_BASE_URL=http://rest:3000 \
-e NODE_RED_BASE_URL=ws://node-red:1880 \
-p 6001:6001 \
hyperledger/vehicle-lifecycle-vda:{{ENV}}
# Start the manufacturing application.
docker run \
-d \
--network composer_default \
--name manufacturing \
-e COMPOSER_BASE_URL=http://rest:3000 \
-e NODE_RED_BASE_URL=ws://node-red:1880 \
-p 6002:6001 \
hyperledger/vehicle-lifecycle-manufacturing:{{ENV}}
# Start the car-builder application.
docker run \
-d \
--network composer_default \
--name car-builder \
-e NODE_RED_BASE_URL=ws://node-red:1880 \
-p 8100:8100 \
hyperledger/vehicle-lifecycle-car-builder:{{ENV}}
# Wait for the applications to start and initialize.
sleep 10
# Kill any other Docker containers.
##docker ps -aq | xargs docker rm -f
# Open the playground in a web browser.
URLS="http://localhost:8080 http://localhost:3000/explorer/ http://localhost:1880 http://localhost:6001 http://localhost:6002 http://localhost:8100"
case "$(uname)" in
"Darwin") open ${URLS}
;;
"Linux") if [ -n "$BROWSER" ] ; then
$BROWSER http://localhost:8080 http://localhost:3000/explorer/ http://localhost:1880 http://localhost:6001 http://localhost:6002 http://localhost:8100
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:8080 http://localhost:3000/explorer/ http://localhost:1880 http://localhost:6001 http://localhost:6002 http://localhost:8100
#elif other types blah blah
else
echo "Could not detect web browser to use - please launch 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
# Exit; this is required as the payload immediately follows.
exit 0