-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
31 lines (21 loc) · 896 Bytes
/
setup.py
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
import os, time, subprocess, re;
print('\nReseting enviorment..\n')
os.system('docker-compose up -d --force-recreate')
print('\nWait for cointainers to warm up...\n')
time.sleep(3)
print('\nInit a docker swarm\n')
r = subprocess.getoutput('docker exec manager docker swarm init')
token = re.search(r'SW\S{1,}', r)[0]
ip = re.search(r'[0-9]{3}\.\S{1,}', r)[0]
print('join token: ' + token)
print('IP manager: ' + ip)
print('\nJoin all nodes\n')
workersToJoin = ['worker1', 'worker2', 'worker3']
for worker in workersToJoin:
command = 'docker exec %s docker swarm join --token %s %s' % (worker, token, ip)
r = subprocess.getoutput(command)
print('%s: %s' % (worker, r))
print('\nShow swarm status\n')
os.system('docker exec manager docker node ls')
print('\nDeploy Portainer\n')
os.system('docker exec manager docker stack deploy -c stack/portainer-agent-stack.yml portainer')