forked from sandstorm-io/sandstorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container-build.py
executable file
·73 lines (53 loc) · 2.01 KB
/
container-build.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
66
67
68
#!/bin/python
import argparse, shlex, subprocess, os, getpass
# from https://stackoverflow.com/a/4760274/259046
def runProcess(exe):
p = subprocess.run(shlex.split(exe), stderr=subprocess.STDOUT)
while(True):
if not isinstance(p, subprocess.CompletedProcess):
retcode = p.poll()
else:
retcode = p.returncode
stdout = p.stdout
print(stdout)
if retcode is not None:
if retcode != 0:
exit(retcode)
else:
break
parser = argparse.ArgumentParser(description='Build Sandstorm using an Ubuntu 20.04 Docker/OCI container')
parser.add_argument("action", choices=["make", "prepare", "shell"], default="make", nargs="?")
parser.add_argument('--container-builder', dest="container_builder", default='podman', help='Command you run for building container from command line')
parser.add_argument('--container-runner', dest="container_runner", default='podman', help='Command you run for running container from command line')
parser.add_argument('args', nargs=argparse.REMAINDER)
args = parser.parse_args()
def prepare():
script ="{builder_cmd} build . -t sandstorm-build".format(builder_cmd=args.container_builder)
print(script)
runProcess(script)
def prepare_cmd(command):
return "{runner_cmd} run --rm -ti \
-v {pwd}:/sandstorm \
-v {pwd}/scripts/podman-entrypoint.sh:/podman-entrypoint.sh \
--userns=keep-id:uid=1000,gid=1000 \
--entrypoint=/podman-entrypoint.sh \
--cap-add=SYS_PTRACE sandstorm-build {command} {args}".format(
runner_cmd=args.container_runner,
pwd=os.getcwd(),
command=command,
args=' '.join(args.args)
)
#
def make():
script = prepare_cmd("make")
print(script)
runProcess(script)
def shell():
script = prepare_cmd("bash")
print(script)
runProcess(script)
prepare()
if (args.action == "make"):
make()
if (args.action == "shell"):
shell()