-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_generator.js
250 lines (223 loc) · 7.02 KB
/
node_generator.js
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
fs = require('fs');
const number = process.argv.slice(2)?.length > 0 ? parseInt(process.argv.slice(2)[0]?.replace('--number=', '')) : 10;
let original_port = 9701;
let port = original_port;
let startNodeFileContent = `#!/bin/bash
set -e
HOST="\${HOST:-0.0.0.0}"
START_PORT="9700"
NODE_NUM="${[...Array(number)].map((_, index) => index + 1).join(' ')}"
if [ ! -d "/home/indy/ledger/sandbox/keys" ]; then
echo "Ledger does not exist - Creating..."
if [ ! -z "$IPS" ]; then
echo von_generate_transactions -s "$IPS" -n "$NODE_NUM"
von_generate_transactions -s "$IPS" -n "$NODE_NUM"
elif [ ! -z "$IP" ]; then
echo von_generate_transactions -i "$IP" -n "$NODE_NUM"
von_generate_transactions -i "$IP" -n "$NODE_NUM"
else
echo von_generate_transactions -n "$NODE_NUM"
von_generate_transactions -n "$NODE_NUM"
fi
fi
cat <<EOF > supervisord.conf
[supervisord]
logfile = /tmp/supervisord.log
logfile_maxbytes = 50MB
logfile_backups=${number}
loglevel = info
pidfile = /tmp/supervisord.pid
nodaemon = true
minfds = 1024
minprocs = 200
umask = 022
user = indy
identifier = supervisor
directory = /tmp
nocleanup = true
childlogdir = /tmp
strip_ansi = false
${[...Array(number)].map((_, index) =>
`[program:node${index+1}]
command=start_indy_node Node${index+1} $HOST ${port++} $HOST ${port++}
directory=/home/indy
stdout_logfile=/tmp/node${index+1}.log
stderr_logfile=/tmp/node${index + 1}.log
`
).join('\n')
}
[program:printlogs]
command=tail -F /tmp/supervisord.log${[...Array(number)].map((_, index) =>` /tmp/node${index+1}.log`).join('')}
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
EOF
echo "Starting indy nodes"
supervisord
`;
fs.writeFile(number + '-dynamic_start_nodes.sh', startNodeFileContent, function (err) {
if (err) return console.log(err);
console.log('Hello World > helloworld.txt');
});
let manageContent = `
-d webserver ${[...Array(number)].map((_, index) => "node"+(index+1)).join(' ')}
-d synctest ${[...Array(number)].map((_, index) => "node"+(index+1)).join(' ')}
`
fs.writeFile(number + '-manage', manageContent, function (err) {
if (err) return console.log(err);
console.log('Hello World > helloworld.txt');
});
let vonGenFileContent = `
if [ ! -z $ipAddresses ]; then
ipsArg="$ipAddresses"
elif [ ! -z $ipAddress ]; then
ipsArg=${[...Array(number)].map((_, index) => "\"\$ipAddress\"").join(',')}
else
ipsArg=${[...Array(number)].map((_, index) => "\"\$DOCKERHOST\"").join(',')}
fi
echo -e \\\\n\\\\n"================================================================================================"
echo -e "Generating genesis transaction file:"
echo -e "nodeArg: \${nodeArg}"
echo -e "ipAddresses: \${ipsArg}"
echo -e "genesisFilePath: \${genesisFilePath}"
echo -e "------------------------------------------------------------------------------------------------"
# Use supplied IP address
echo -e generate_indy_pool_transactions \\
--nodes ${number} \\
--clients 0 \\
$nodeArg \\
--ips "$ipsArg" \\
\\\\n
generate_indy_pool_transactions \\
--nodes ${number} \\
--clients 0 \\
$nodeArg \\
--ips "$ipsArg"
`;
fs.writeFile(number + '-von_generate_transactions', vonGenFileContent, function (err) {
if (err) return console.log(err);
console.log('Hello World > helloworld.txt');
});
port = original_port;
let dockerComposeFileContent = `version: '3'
services:
#
# Client
#
client:
image: von-network-base
command: 'bash -c ''./scripts/start_client.sh'''
environment:
- IP=\${IP}
- IPS=\${IPS}
- DOCKERHOST=\${DOCKERHOST}
- RUST_LOG=\${RUST_LOG}
networks:
- von
volumes:
- client-data:/home/indy/.indy_client
- ./tmp:/tmp
#
# Webserver
#
webserver:
image: von-network-base
command: 'bash -c ''sleep 10; ./scripts/start_webserver.sh;'''
environment:
- IP=\${IP}
- IPS=\${IPS}
- DOCKERHOST=\${DOCKERHOST}
- LOG_LEVEL=\${LOG_LEVEL}
- RUST_LOG=\${RUST_LOG}
- GENESIS_URL=\${GENESIS_URL}
- ANONYMOUS=\${ANONYMOUS}
- LEDGER_SEED=\${LEDGER_SEED}
- LEDGER_CACHE_PATH=\${LEDGER_CACHE_PATH}
- MAX_FETCH=\${MAX_FETCH:-50000}
- RESYNC_TIME=\${RESYNC_TIME:-120}
- REGISTER_NEW_DIDS=\${REGISTER_NEW_DIDS:-True}
- LEDGER_INSTANCE_NAME=\${LEDGER_INSTANCE_NAME:-localhost}
- WEB_ANALYTICS_SCRIPT=\${WEB_ANALYTICS_SCRIPT}
- INFO_SITE_TEXT=\${INFO_SITE_TEXT}
- INFO_SITE_URL=\${INFO_SITE_URL}
networks:
- von
ports:
- \${WEB_SERVER_HOST_PORT:-9000}:8000
volumes:
- ./config:/home/indy/config
- ./server:/home/indy/server
- webserver-cli:/home/indy/.indy-cli
- webserver-ledger:/home/indy/ledger
#
# Synchronization test
#
synctest:
image: von-network-base
command: 'bash -c ''./scripts/start_synctest.sh'''
environment:
- IP=\${IP}
- IPS=\${IPS}
- DOCKERHOST=\${DOCKERHOST}
- LOG_LEVEL=\${LOG_LEVEL}
- RUST_LOG=\${RUST_LOG}
networks:
- von
ports:
- \${WEB_SERVER_HOST_PORT:-9000}:8000
volumes:
- ./config:/home/indy/config
- ./server:/home/indy/server
- webserver-cli:/home/indy/.indy-cli
- webserver-ledger:/home/indy/ledger
#
# Nodes
#
nodes:
image: von-network-base
command: 'bash -c ''./scripts/start_nodes.sh'''
networks:
- von
ports:
${[...Array(number * 2)].map((_, index) => ` - ${port}:${port++}`).join('\n')}
environment:
- IP=\${IP}
- IPS=\${IPS}
- DOCKERHOST=\${DOCKERHOST}
- LOG_LEVEL=\${LOG_LEVEL}
- RUST_LOG=\${RUST_LOG}
volumes:
- nodes-data:/home/indy/ledger
${temp(original_port)}
networks:
von:
volumes:
client-data:
webserver-cli:
webserver-ledger:
${[...Array(number)].map((_, index) => ` node${index+1}-data:`).join('\n')}
nodes-data:
`;
fs.writeFile(number + '-dynamic_docker-compose.yaml', dockerComposeFileContent, function (err) {
if (err) return console.log(err);
console.log('Hello World > helloworld.txt');
});
function temp (port) {
return ([...Array(number)].map(
(_, index) =>
` node${index+1}:
image: von-network-base
command: 'bash -c ''./scripts/start_node.sh ${index + 1}'''
networks:
- von
ports:
- ${port}:${port++}
- ${port}:${port++}
environment:
- IP=\${IP}
- IPS=\${IPS}
- DOCKERHOST=\${DOCKERHOST}
- LOG_LEVEL=\${LOG_LEVEL}
- RUST_LOG=\${RUST_LOG}
volumes:
- node${index + 1}-data:/home/indy/ledger\n`).join('\n'))
}