-
Notifications
You must be signed in to change notification settings - Fork 13
/
gen-dockerfiles
executable file
·54 lines (41 loc) · 1.43 KB
/
gen-dockerfiles
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
#!/usr/bin/env python3
import os
from urllib import request
RUST_VERSION = '1.81.0'
RUSTUP_VERSION = '1.27.1'
DISTRIBUTIONS = {
# Ubuntu
'bionic': 'x86_64-unknown-linux-gnu',
# CentOS
'centos-7': 'x86_64-unknown-linux-gnu',
# Arch64
'aarch64': 'aarch64-unknown-linux-gnu',
}
def fetch_rustup_hash(RUST_ARCH):
url = f'https://static.rust-lang.org/rustup/archive/{RUSTUP_VERSION}/{RUST_ARCH}/rustup-init.sha256'
with request.urlopen(url) as f:
return f.read().decode('utf-8').split()[0]
def load_template(dist):
with open(f'templates/{dist}.Dockerfile', 'r') as f:
return f.read()
def save_dockerfile(dist, contents):
filepath = f'{dist}/Dockerfile'
filedir = os.path.dirname(filepath)
if filedir and not os.path.exists(filedir):
os.makedirs(filedir)
with open(filepath, 'w') as f:
f.write(contents)
def generate_dockerfile(dist, rustup_sha256, RUST_ARCH):
template = load_template(dist)
rendered = template \
.replace('%%RUST_VERSION%%', RUST_VERSION) \
.replace('%%RUSTUP_VERSION%%', RUSTUP_VERSION) \
.replace('%%RUSTUP_SHA256%%', rustup_sha256) \
.replace('%%RUST_ARCH%%', RUST_ARCH)
save_dockerfile(dist, rendered)
def main():
for dist, arch in DISTRIBUTIONS.items():
rustup_sha256 = fetch_rustup_hash(arch)
generate_dockerfile(dist, rustup_sha256, arch)
if __name__ == '__main__':
main()