-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_builds.py
executable file
·65 lines (57 loc) · 1.95 KB
/
create_builds.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
#!/usr/bin/env python3
"""Create buildx commands"""
import os
import sys
import datetime
PLATFORMS = ["linux/amd64", "linux/arm64"]
TARGETS = ["pyenv", "tox-base"]
VARIANTS = ["alpine-3.19", "debian-bullseye", "ubuntu-jammy"]
VARIANTS += ["alpine-3.20", "debian-bookworm", "ubuntu-noble"]
# Which distro version gets the distro name tag
DISTRO_DEFAULT_VERSIONS = {
"alpine": "3.20",
"debian": "bookworm",
"ubuntu": "noble",
}
def print_bakefile(reponame: str, target: str) -> None:
"""Print the bakefile"""
hcl_targets = ""
for variant in VARIANTS:
isodate = datetime.datetime.utcnow().date().isoformat()
distro, version = variant.split("-")
distrotag = ""
if version == DISTRO_DEFAULT_VERSIONS[distro]:
distrotag = f'"{reponame}/{target}:{distro}", "{reponame}/{target}:{distro}-{isodate}", '
dockerfile = f"Dockerfile_{distro}"
hcl_targets += f"""
target "{target}-{variant.replace(".","")}" {{
dockerfile = "{dockerfile}"
platforms = [{", ".join(f'"{platform}"' for platform in PLATFORMS)}]
target = "{target}"
args = {{
IMAGE_VERSION = "{version}"
}}
tags = [{distrotag}"{reponame}/{target}:{distro}-{version}", "{reponame}/{target}:{distro}-{version}-{isodate}"]
}}
"""
print(
f"""
// To build and push images, redirect this output to a file named "{target}.hcl" and run:
//
// docker login
// docker buildx bake --push --file ./{target}.hcl
group "default" {{
targets = [{", ".join(f'"{target}-{variant.replace(".","")}"' for variant in VARIANTS)}]
}}"""
)
print(hcl_targets)
if __name__ == "__main__":
envreponame = os.environ.get("DHUBREPO")
if not envreponame:
print("Define DHUBREPO")
sys.exit(1)
if len(sys.argv) != 2 or not sys.argv[1] in TARGETS:
print(f"""Specify target, one of: {", ".join(TARGETS)}""")
sys.exit(1)
clitarget = sys.argv[1]
print_bakefile(envreponame, clitarget)