-
Notifications
You must be signed in to change notification settings - Fork 15
/
plebnet_generate.py
executable file
·106 lines (83 loc) · 3.24 KB
/
plebnet_generate.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
#!/usr/bin/env python3
# Generates docker-compose from command line.
#
# For each service identified at command line, this we identify other dependent services and add them to the config.
# +
import sys
sys.path.append('.')
sys.path.append("/usr/local/lib/python3.7/site-packages")
sys.path.append("/usr/local/lib/python3.8/site-packages")
sys.path.append("/usr/local/lib/python3.9/site-packages")
sys.path.append("/usr/local/lib/python3.10/site-packages")
sys.path.append("/usr/local/lib/python3.11/site-packages")
#print(sys.path)
from omegaconf import OmegaConf
architectures = {
"Intel x64": 'x86_64-linux-gnu',
'OSX 64-bit': 'aarch64-linux-gnu',
'arm 32-bit': 'arm-linux-gnueabihf',
'ARM64 linux': 'aarch64-linux-gnu',
}
# +
cli_args = OmegaConf.from_cli()
try:
triplet = cli_args['TRIPLET']
except KeyError:
print('Need to supply TRIPLET. Supported architectures:')
for k, v in architectures.items():
print('\t{}: TRIPLET={}'.format(k, v))
sys.exit()
conf = OmegaConf.load('docker-compose.yaml.template')
# merge in architecture
conf = OmegaConf.merge(OmegaConf.create(dict(TRIPLET=triplet)), conf)
if 'services' in cli_args:
services = cli_args['services']
if services is None:
services = [service for service in conf.services]
else:
services = cli_args['services'].split(',')
else:
print('Using default services')
services = [service for service in conf.services]
print('requested services:\t{}'.format(', '.join(sorted(services))))
def get_services(services, required_services=set()):
"""recursively retrieve dependent services"""
# print('retrieving requirements for {}'.format(', '.join(sorted(services))))
for service_name in list(services):
if service_name in conf.services:
required_services.add(service_name)
depends = conf.services[service_name].get('depends_on', [])
for service in depends:
required_services.add(service)
links = conf.services[service_name].get('links', [])
for service in links:
required_services.add(service)
else:
print('{} service not yet available in plebnet-playground!'.format(
service_name))
print('available services:')
for service in conf.services:
print('\t{}'.format(service))
print('Add the configuration for {} to docker-compose.yaml.template and run again.'.format(
service_name))
sys.exit()
if set(services) == required_services:
return required_services
return get_services(required_services, required_services)
required_services = get_services(services)
print('required services:\t{}'.format(', '.join(sorted(required_services))))
for service_name in list(conf.services):
if service_name not in required_services:
conf.services.pop(service_name)
# dashboard keyword
conf['USE_TEST_DATA'] = cli_args.get('TRIPLET', False)
try:
OmegaConf.resolve(conf)
except:
print(OmegaConf.to_yaml(conf))
raise
conf.pop('TRIPLET')
conf.pop('USE_TEST_DATA')
with open('docker-compose.yaml', 'w') as f:
f.write(OmegaConf.to_yaml(conf))
print('wrote required services to docker-compose.yaml')