forked from Ellipsis-Labs/solana-verifiable-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_dockerfiles.py
96 lines (82 loc) · 2.88 KB
/
generate_dockerfiles.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
import subprocess
import os
import argparse
import requests
parser = argparse.ArgumentParser()
parser.add_argument("--upload", action="store_true")
parser.add_argument("--skip_cache", action="store_true")
args = parser.parse_args()
VERSION_PLACEHOLDER = "$VERSION"
base_dockerfile_text = f"""
FROM --platform=linux/amd64 rust@sha256:79892de83d1af9109c47a4566a24a0b240348bb8c088f1bccc52645c4c70ec39
RUN apt-get update && apt-get install -qy git gnutls-bin
RUN sh -c "$(curl -sSfL https://release.solana.com/{VERSION_PLACEHOLDER}/install)"
ENV PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
WORKDIR /build
CMD /bin/bash
"""
output = subprocess.check_output(
["git", "ls-remote", "--tags", "https://github.com/solana-labs/solana"]
)
def check_version(version_str):
try:
# Ignore this one
if version_str == "v1.14.0":
return False
[major, minor, _patch] = version_str.strip("v").split(".")
# Ignore 1.15.x
return int(major) >= 1 and int(minor) >= 14 and int(minor) != 15
except Exception as e:
return False
tags = list(
filter(
check_version,
[
elem.split("\t")[1].split("/")[-1]
for elem in output.decode("utf-8").split("\n")
if elem
],
)
)
dockerfiles = {}
for release in tags:
dockerfile = base_dockerfile_text.replace(VERSION_PLACEHOLDER, release).lstrip("\n")
path = f"docker/{release}.Dockerfile"
with open(path, "w") as f:
f.write(dockerfile)
dockerfiles[release] = path
if args.upload:
digest_set = set()
if not args.skip_cache:
print("Fetching existing images")
response = requests.get(
"https://hub.docker.com/v2/namespaces/ellipsislabs/repositories/solana/tags?page_size=1000"
)
for result in response.json()["results"]:
if result["name"] != "latest":
try:
digest_set.add(result["name"])
except Exception as e:
print(e)
continue
print("Uploading all Dockerfiles")
for tag, dockerfile in dockerfiles.items():
# Strip the `v` from the tag to keep the versions consistent in Docker
stripped_tag = tag.strip("v")
if stripped_tag in digest_set:
print(f"Already built image for {stripped_tag}, skipping")
continue
version_tag = f"solana:{stripped_tag}"
print(version_tag)
current_directory = os.getcwd()
res = subprocess.call(
f"docker build -t {version_tag} - < {current_directory}/{dockerfile}",
shell=True,
)
if res == 0:
subprocess.call(
f"docker tag {version_tag} ellipsislabs/{version_tag}", shell=True
)
subprocess.call(f"docker push ellipsislabs/{version_tag}", shell=True)
else:
continue