-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
93 lines (66 loc) · 2.48 KB
/
build.py
File metadata and controls
93 lines (66 loc) · 2.48 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
92
93
import os
import subprocess
import sys
from typing import List
from result import Err, Ok, Result, is_err, is_ok
from utils import discover_versions
def main():
if len(sys.argv) > 1:
versions = sys.argv[1:]
result = build_all(versions)
else:
result = build_all()
if is_ok(result):
print(f"Build process succeeded: {result.unwrap()}")
elif is_err(result):
print(f"Build process failed: {result.unwrap_err()}")
exit(1)
def build(tag: str) -> Result[str, str]:
"""
Build a Docker image with the specified tag.
Args:
tag: The tag of the image
Returns:
Result[str, str]: Ok with success message or Err with error message
"""
try:
image_name = f"endkind/velocity:{tag}"
context_path = f"./versions/{tag}"
if not os.path.exists(context_path):
return Err(f"Build context path '{context_path}' does not exist")
cmd = ["docker", "build", "-t", image_name, context_path]
print(f"Building Docker image: {image_name}")
print(f"Build context: {context_path}")
print(f"Command: {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
return Ok(f"Docker image '{image_name}' built successfully")
except subprocess.CalledProcessError as e:
error_msg = f"Docker build failed: {e.stderr if e.stderr else e.stdout}"
return Err(error_msg)
except Exception as e:
return Err(f"Unexpected error: {str(e)}")
def build_all(versions: List[str] = discover_versions()) -> Result[str, str]:
"""
Build all available Docker images by auto-discovering available configurations.
"""
if not versions:
return Err("No build configurations found!")
print(f"Found {len(versions)} build configurations:")
for version in versions:
print(f" - velocity/{version}")
print("\nStarting builds...\n")
success_count = 0
for version in versions:
print(f"--- Building velocity:{version} ---")
result = build(version)
if is_ok(result):
print(f"✅ {result.unwrap()}")
success_count += 1
else:
print(f"❌ {result.unwrap_err()}")
print()
if success_count < len(versions):
return Err(f"Build incomplete: only {success_count}/{len(versions)} succeeded")
return Ok(f"Build complete: {success_count}/{len(versions)} succeeded")
if __name__ == "__main__":
main()