-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_images.onyx
48 lines (41 loc) · 1.44 KB
/
build_images.onyx
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
use core {*}
main :: () {
args := os.args()
no_cache := Slice.some(args, [x](x == "--no-cache"))
tag := Slice.find_opt(args, [x](str.starts_with(x, "--tag=")))
|> Optional.transform(x => {
_, prefix := str.bisect(x, '=')
return prefix
})
build_files := os.list_directory("./build")
|> Iterator.map(x => x->name_copy())
|> Iterator.collect()
for file in build_files {
build_name, _ := str.bisect(file, '.')
logf(.Info, "========= Building {} =========\n", build_name)
command := os.command()
|> .path("docker")
|> .args(.["build"])
|> .args(.["-t", tprintf("onyx:{}", build_name)])
|> .args(.["-f", tprintf("./build/{}", file)])
if no_cache {
command = os.Command.args(command, .["--no-cache"])
}
output := command
|> .args(.["."])
|> .run()
if output != .Success {
printf("\x1b[91mFailed to build '{}'\x1b[0m\n", build_name)
} else {
tag->with([prefix] {
os.command()
|> .path("docker")
|> .args(.["tag"])
|> .args(.[tprintf("onyx:{}", build_name)])
|> .args(.[tprintf("{}:{}", prefix, build_name)])
|> .run()
|> printf("Tag result: {}\n", _)
})
}
}
}