forked from stellar/stellar-cli-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_image.py
More file actions
executable file
·91 lines (77 loc) · 3.16 KB
/
Copy pathbuild_image.py
File metadata and controls
executable file
·91 lines (77 loc) · 3.16 KB
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
#!/usr/bin/env -S uv run python
"""Build a single stellar-cli image locally for a declared (cli, rust base) pair.
Looks up the pinned base image digest and stellar-cli commit SHA from
builds.json so the build inputs come from one source of truth.
"""
import argparse
import datetime
import sys
import tag_names
from lib import builds, common, runner, rust_keys
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("--stellar-cli-version", required=True, metavar="V")
parser.add_argument("--rust-version", required=True, metavar="KEY")
parser.add_argument("--rust-image-digest", required=True, metavar="DIGEST")
parser.add_argument("--platform", default="", metavar="P")
parser.add_argument("--tag", default="", metavar="REF")
parser.add_argument("--source-repo", default="stellar/stellar-cli-docker", metavar="SLUG")
return parser
def main(argv: list[str] | None = None) -> int:
args = build_parser().parse_args(argv)
common.preflight_checks(["buildx"])
data = builds.load()
rust_digest = args.rust_image_digest
try:
builds.assert_pair_declared(
data, args.stellar_cli_version, f"{args.rust_version}@{rust_digest}"
)
stellar_ref = builds.stellar_cli_ref(data, args.stellar_cli_version)
parsed = rust_keys.parse(args.rust_version)
entry = builds.find_cli(data, args.stellar_cli_version)
cli_rust_pin = entry.get("cli_rust_version") if entry else None
cli_rust_digest = builds.digest_of(cli_rust_pin) if cli_rust_pin else rust_digest
except ValueError as exc:
common.die(str(exc))
tag = args.tag or "stellar-cli:" + tag_names.compose_tag(
stellar_cli_version=args.stellar_cli_version,
rust_version=args.rust_version,
)
build_date = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%dT%H:%M:%SZ")
common.log(f"building {tag}")
common.log(f" stellar-cli {args.stellar_cli_version} ({stellar_ref})")
common.log(f" rust {args.rust_version} ({rust_digest})")
common.log(f" cli-build rust ({cli_rust_digest})")
common.log(f" base rust:{parsed.version}-{parsed.suffix}")
common.log(f" platform {args.platform or '<host native>'}")
cmd = ["docker", "buildx", "build"]
if args.platform:
cmd += ["--platform", args.platform]
cmd += [
"--load",
"--build-arg",
f"RUST_VERSION={parsed.version}",
"--build-arg",
f"RUST_BASE_SUFFIX={parsed.suffix}",
"--build-arg",
f"RUST_IMAGE_DIGEST={rust_digest}",
"--build-arg",
f"CLI_RUST_IMAGE_DIGEST={cli_rust_digest}",
"--build-arg",
f"STELLAR_CLI_REV={stellar_ref}",
"--build-arg",
f"STELLAR_CLI_VERSION={args.stellar_cli_version}",
"--build-arg",
f"BUILD_DATE={build_date}",
"--build-arg",
f"SOURCE_REPO={args.source_repo}",
"--tag",
tag,
str(common.repo_root()),
]
runner.run(cmd)
common.log("")
common.log(f"built: {tag}")
return 0
if __name__ == "__main__":
sys.exit(main())