forked from brettviren/wire-cell-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
75 lines (58 loc) · 2.49 KB
/
wscript
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
from pathlib import Path
from waflib.Logs import debug, info, error, warn
from waflib.Utils import subst_vars
def options(opt):
opt.add_option("--owner", default="wirecell",
help="Give the 'owner' name used in naming podman images")
def configure(cfg):
cfg.find_program("podman", var="PODMAN")
cfg.find_program("singularity", var="SINGULARITY", mandatory=False)
def build_image(task):
dctx = task.inputs[0].parent
flag = task.outputs[0]
name = task.generator.image
slashless = name.replace('/','-')
log = f'podman-build-{slashless}.log'
cmd = f'${{PODMAN}} build -t {name} {dctx}'
cmd += f' | grep -A2 "Successfully tagged localhost/{name}" | tee {log} && tail -1 {log} > {flag}'
# cmd += f' && echo {task.generator.image} > {flag}'
cmd = subst_vars(cmd, task.env)
debug(f'podman: {cmd}')
return task.exec_command(cmd)
def dump_image(task):
out = task.outputs[0]
cmd = f'${{PODMAN}} save --format oci-archive {task.generator.image} -o {out}'
cmd = subst_vars(cmd, task.env)
debug(f'podman: {cmd}')
return task.exec_command(cmd)
# $ singularity build sluser.sif oci-archive://sluser.tar
def build(bld):
owner = bld.options.owner
image_deps = dict(
slscisoft={},
sluser=dict(deps=("slscisoft",), sing=True),
)
for iname, desc in image_deps.items():
deps = desc.get("deps", ())
sing = desc.get("sing", False)
image = f'{owner}/{iname}'
fname = f'{owner}-{iname}'
dfile = bld.path.find_resource(f'images/{iname}/Containerfile')
pfile = bld.path.find_or_declare(f'{fname}.podman')
ffiles = [bld.path.find_or_declare(f'{owner}-{n}.podman') for n in deps]
debug(f'build: {iname} deps: {ffiles}')
tfile = bld.path.find_or_declare(f'{fname}.tar')
sfile = bld.path.find_or_declare(f'{fname}.sif')
bld(name=f'build-{fname}',
rule=build_image, image=image,
source=[dfile] + ffiles,
target=pfile)
if sing and 'SINGULARITY' in bld.env:
debug(f'build: {iname} dumping to tar and singularity')
bld(name=f'dump-{fname}',
rule=dump_image, image=image,
source=pfile, target=tfile)
bld(name=f'sing-{fname}',
rule='${SINGULARITY} build --force ${TGT[0]} oci-archive://${SRC[0]}',
source=tfile, target=sfile)
bld.install_files('${PREFIX}/share/containers/singularity', sfile)