-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_spotters.py
60 lines (52 loc) · 1.61 KB
/
generate_spotters.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
import requests
def fetch_parameters(repo):
url = f"https://raw.githubusercontent.com/exorde-labs/{repo}/main/meta.json"
headers = {"Accept": "application/vnd.github+json"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
if data['parameters']:
return data['parameters']
if response.status_code == 404:
return []
else:
raise Exception("An error occured while retrieving package metadata")
def fetch_repos(topic, organization):
url = f"https://api.github.com/search/repositories?q=topic:{topic}+org:{organization}"
headers = {"Accept": "application/vnd.github+json"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
repo_names = [item['full_name'].split('/')[1] for item in data['items']]
return repo_names
else:
return []
repos = fetch_repos("exorde-spot-driver", "exorde-labs")
print("""
version: '3'
services:
""", end='')
for repo in repos:
parameters = fetch_parameters(repo)
print(f"""
{repo}:
restart: always
labels:
- "network.exorde.monitor=true"
- "network.exorde.service=spot"
image: exordelabs/spot{repo}
networks:
- exorde-network
init: true
deploy:
""", end='')
print(' replicas: ${' + repo[:3] + ':-0}')
if len(parameters) > 0:
print(' environment:')
for parameter in parameters:
print(f" - {parameter}" + "=${" + f"{parameter}" + "}")
print("""
networks:
exorde-network:
external: true
""")