forked from tata1mg/notifyone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgateway_setup.py
More file actions
62 lines (50 loc) · 2.44 KB
/
gateway_setup.py
File metadata and controls
62 lines (50 loc) · 2.44 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
import subprocess
import json
import os
from utils import extract_values
from sys import platform
from components.gateway import SOURCE as GATEWAY_SOURCE
def setup_gateway():
print("\nSetting up notifyone-gateway.....\n")
_res = subprocess.run(["git clone {}".format(GATEWAY_SOURCE)], shell=True,
capture_output=True)
if _res.returncode != 0:
print(str(_res.stderr.decode('utf-8')))
#exit(1)
os.chdir('notifyone-gateway')
_res = subprocess.run(['cp config_template.json config.json'], shell=True, capture_output=True)
if _res.returncode != 0:
print(str(_res.stderr.decode('utf-8')))
exit(1)
with open('config.json', 'r') as c:
_gateway_config = json.load(c)
_gateway_port = str(_gateway_config.get("PORT") or 9401)
_gateway_queue_names = extract_values(_gateway_config, "QUEUE_NAME")
if platform.lower() == 'darwin':
_gateway_config['NOTIFICATION_SERVICE']['HOST'] = 'http://host.docker.internal:9402'
_gateway_config['TRIGGER_NOTIFICATIONS']['SQS']['SQS_ENDPOINT_URL'] = 'http://host.docker.internal:4566'
with open('config.json', 'w') as f:
json.dump(_gateway_config, f)
# create local stack queues
for _q in _gateway_queue_names:
_res = subprocess.run(["docker exec -i $(docker ps | grep localstack | awk '{print $1}') awslocal sqs create-queue --queue-name " + _q],
shell=True, capture_output=True)
if _res.returncode != 0:
print("\nError in creating queue {}\n".format(_q))
print(_res.stderr.decode('utf-8'))
else:
pass
_stat = subprocess.run(['docker rm --force notifyone-gateway'], shell=True)
_stat = subprocess.run(["docker image rm notifyone-gateway"], shell=True)
_res = subprocess.run(['docker build . --tag notifyone-gateway --build-arg SERVICE_NAME=notifyone_gateway'],
shell=True, capture_output=True)
if _res.returncode != 0:
print(str(_res.stderr.decode('utf-8')))
exit(1)
_res = subprocess.run([
'docker run -p ' + _gateway_port + ':' + _gateway_port + ' --detach --name notifyone-gateway notifyone-gateway'],
shell=True, capture_output=True)
if _res.returncode != 0:
print(str(_res.stderr.decode('utf-8')))
exit(1)
print("\nnotifyone-gateway setup completed\n")