-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathnotify_setup.py
141 lines (114 loc) · 5.98 KB
/
notify_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
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
import subprocess
import os
import sys
from sys import platform
from gateway_setup import setup_gateway
from core_setup import setup_core
from handler_setup import setup_handler
from dashboard_setup import setup_dashboard
sys_platform = sys.argv[1] if len(sys.argv) > 1 else "linux/amd64"
cms_api_endpoint = sys.argv[2] if len(sys.argv) > 2 else ""
print("Building for system platform - {}".format(sys_platform))
_docker_check_res = subprocess.run(['docker info'], shell=True, capture_output=True)
if _docker_check_res.returncode != 0:
print("Either Docker is not installed or not running\n"+(str(_docker_check_res.stderr.decode('utf-8'))))
exit(1)
print("\n Setting up Postgres on Docker\n")
_res = subprocess.run(['docker pull postgres:14.5'], shell=True, capture_output=True)
if _res.returncode != 0:
print(str(_res.stderr.decode('utf-8')))
exit(1)
_stat = subprocess.run(['docker rm --force postgres_notify'], shell=True)
_res = subprocess.run(["docker run --detach -p5432:5432 -e POSTGRES_PASSWORD='postgres' -e POSTGRES_USER=postgres --name postgres_notify postgres:14.5"], shell=True, capture_output=True)
if _res.returncode != 0:
print(str(_res.stderr.decode('utf-8')))
exit(1)
print("\n Setting up Redis on Docker\n")
_stat = subprocess.run(['docker rm --force redis_notify'], shell=True)
_res = subprocess.run(["docker run --detach --name redis_notify -p 6379:6379 -d redis"], shell=True, capture_output=True)
if _res.returncode != 0:
print(str(_res.stderr.decode('utf-8')))
exit(1)
print("\n Setting up localstack\n")
# install localstack
_res = subprocess.run(['localstack --version'], shell=True, capture_output=True)
if _res.returncode != 0:
print("Localstack not installed \n"+(str(_docker_check_res.stderr.decode('utf-8'))))
print("\n installing localstack \n")
_localstack_res = subprocess.run(['python3 -m pip install --force-reinstall localstack'], shell=True, capture_output=True)
if _localstack_res.returncode != 0:
print(str(_localstack_res.stderr.decode('utf-8')))
exit(1)
else:
pass
else:
pass
_localstack_start_res = subprocess.run(['localstack start -d'], shell=True, capture_output=True)
if _localstack_start_res.returncode != 0:
print(str(_localstack_start_res.stderr.decode('utf-8')))
exit(1)
else:
pass
# print("setup aws default region to eu-west-2")
# _res = subprocess.run(["rm /tmp/config"],
# shell=True, capture_output=True)
# _res = subprocess.run(['touch /tmp/config | echo "[default]" >> /tmp/config | echo "region=eu-west-2" >> /tmp/config'],
# shell=True, capture_output=True)
# if _res.returncode != 0:
# print("\nError in creating localstck aws config file\n")
# print(_res.stderr.decode('utf-8'))
# else:
# pass
# _res = subprocess.run(
# ["docker exec -i $(docker ps | grep localstack | awk '{print $1}') mkdir /root/.aws"],
# shell=True, capture_output=True)
# _res = subprocess.run(
# ["docker cp /tmp/config $(docker ps | grep localstack | awk '{print $1}'):/root/.aws/config"],
# shell=True, capture_output=True)
# if _res.returncode != 0:
# print("\nError in copying localstck aws config file to localstack container\n")
# print(_res.stderr.decode('utf-8'))
# else:
# pass
print("### Init component submodules........")
subprocess.run('git submodule init', shell=True, capture_output=True)
print("### Update component submodules........")
subprocess.run('git submodule update', shell=True, capture_output=True)
# Pull required python slim image
print("Pull required python slim image - python:3.9.10-slim")
_res = subprocess.run('docker pull --platform="{}" python:3.9.10-slim'.format(sys_platform), shell=True, capture_output=True)
if _res.returncode != 0:
print(str(_res.stderr.decode('utf-8')))
exit(1)
# Create a docker network and connect components to the network
if platform == "linux":
subprocess.run('docker network create notifyone-network', shell=True, capture_output=True)
subprocess.run('docker network connect notifyone-network postgres_notify', shell=True, capture_output=True)
subprocess.run('docker network connect notifyone-network redis_notify', shell=True, capture_output=True)
subprocess.run('docker network connect notifyone-network localstack-main', shell=True, capture_output=True)
setup_gateway(sys_platform)
os.chdir('../')
setup_core(sys_platform)
os.chdir('../')
setup_handler(sys_platform)
os.chdir('../')
setup_dashboard(sys_platform, cms_api_endpoint)
os.chdir('../')
if platform == "linux":
subprocess.run('docker network connect notifyone-network notifyone-gateway', shell=True, capture_output=True)
subprocess.run('docker network connect notifyone-network notifyone-core', shell=True, capture_output=True)
subprocess.run('docker network connect notifyone-network notifyone-handler', shell=True, capture_output=True)
subprocess.run('docker network connect notifyone-network notifyone-dashboard', shell=True, capture_output=True)
_res = subprocess.run(["docker exec -i $(docker ps | grep notifyone-core | awk '{print $1}') python3 database.py upgrade "],
shell=True, capture_output=True)
if _res.returncode != 0:
print("\nError in DB upgrade\n")
print(_res.stderr.decode('utf-8'))
else:
print("\nDB upgrade Successful\n")
print('##### Congratulations! NotifyOne system setup Completed #####')
print('Service Hosts - \n\t notifyone-dashboard : http://localhost:8001 \n\t notifyone-gateway : http://localhost:9401 \n\t notifyone-core : http://localhost:9402 \n\t notifyone-handler : http://localhost:9403')
print('Create App API documentation - \n\t http://localhost:9402/swagger/#/Apps/post_apps')
print('Create Event API documentation - \n\t http://localhost:9402/swagger/#/Events/post_event_create')
print('Send-Notification API documentation - \n\t http://localhost:9401/swagger/#/event_notification/post_send_notification')
print('Get-Notification-Detail API documentation - \n\t http://localhost:9401/swagger/#/event_notification/get_get_notification')