forked from rphovley/node-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_nodes.js
More file actions
62 lines (53 loc) · 1.71 KB
/
run_nodes.js
File metadata and controls
62 lines (53 loc) · 1.71 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
const fs = require('fs')
const {profiles, sendgridKey} = require('./config.json')
const { execSync } = require('child_process')
const baseTemplate = {
version: '3',
services: {
},
volumes:{
'hyper-node-volume1': {}
}
}
let previous = ''
for(let i=0; i<profiles.length; i++){
const profile = profiles[i]
baseTemplate.services[`uptime_${profile.serviceName}`] = {
build: 'node-uptime/.',
environment: [
`MIN_NUM_PODS=${profile.nodeCount}`,
`NOTIFY_EMAIL=${profile.notifyEmail}`,
`SENDGRID_KEY=${sendgridKey}`
],
volumes: ['/var/run/docker.sock:/var/run/docker.sock']
}
for(let j=0; j<profile.nodeCount; j++){
const nodeName = `hyper-node_${profile.serviceName}_${j}`
let current = {
build: '.',
restart: 'always',
environment:[
`NODE_NAME=${nodeName}`,
`NODE_USER_ID=${profile.nodeUserId}`,
`NODE_LOG_LEVEL=${profile.logLevel || 'debug'}`,
`NODE_WAIT=${j}`
],
volumes: [`hyper-node-volume1:/root/node_${nodeName}`]
}
if(previous){
current.depends_on = [previous]
}
baseTemplate.services[`hypernode_${profile.serviceName}_${j}`] = current
previous = `hypernode_${profile.serviceName}_${j}`
}
}
// console.log(JSON.stringify(baseTemplate, null, 2))
fs.writeFileSync('docker-compose.generated.yml', JSON.stringify(baseTemplate, null, 2))
try {
console.log('Stopping any existing services...')
execSync('docker-compose -f docker-compose.generated.yml down', { stdio: 'inherit' })
console.log('Starting new services...')
execSync('docker-compose -f docker-compose.generated.yml up -d', { stdio: 'inherit' })
} catch (error) {
console.error('Error executing docker-compose:', error)
}