forked from Ellipsis-Labs/solana-verifiable-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_image_whitelist.py
82 lines (71 loc) · 2.65 KB
/
update_image_whitelist.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
import re
import requests
import os
github_token = os.environ.get('GITHUB_TOKEN')
use_ghcr = os.environ.get('USE_GHCR', 'false').lower() == 'true'
headers = {'Authorization': f'Bearer {github_token}'}
if use_ghcr:
url = "https://api.github.com/orgs/Ellipsis-Labs/packages/container/solana/versions?per_page=100"
results = []
while url:
response = requests.get(url, headers=headers)
if response.status_code != 200:
raise Exception(f"Failed to get Docker images: {response.status_code} {response.text}")
results.extend(response.json())
# Check for pagination
url = None
if 'Link' in response.headers:
links = response.headers['Link']
for link in links.split(','):
if 'rel="next"' in link:
url = link[link.find('<') + 1:link.find('>')]
break
if response.status_code != 200:
raise Exception(f"Failed to get Docker images: {response.status_code} {response.text}")
else:
response = requests.get(
"https://hub.docker.com/v2/namespaces/ellipsislabs/repositories/solana/tags?page_size=1000"
)
if response.status_code != 200:
raise Exception(f"Failed to get Docker images: {response.status_code} {response.text}")
results = response.json()["results"]
digest_map = {}
for result in results:
if use_ghcr:
# For GHCR, extract version from metadata
metadata = result.get("metadata", {})
container = metadata.get("container", {})
tags = container.get("tags", [])
for tag in tags:
match = re.match(r'(\d+)\.(\d+)\.(\d+)', tag)
if match:
major, minor, patch = map(int, match.groups())
digest_map[(major, minor, patch)] = result["name"] # "name" contains the digest for GHCR
break
else:
if result["name"] != "latest":
try:
major, minor, patch = list(map(int, result["name"].split(".")))
digest_map[(major, minor, patch)] = result["digest"]
except Exception as e:
print(e)
continue
entries = []
for k, v in sorted(digest_map.items()):
entries.append(f' m.insert({k}, "{v}");')
mappings = "\n".join(entries)
code = f"""
/// THIS FILE IS AUTOGENERATED. DO NOT MODIFY
use lazy_static::lazy_static;
use std::collections::BTreeMap;
lazy_static! {{
pub static ref IMAGE_MAP: BTreeMap<(u32, u32, u32), &'static str> = {{
let mut m = BTreeMap::new();
{mappings}
m
}};
}}
"""
print(code)
with open("src/image_config.rs", "w") as f:
f.write(code.lstrip("\n"))