forked from omec-project/bess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer_build.py
executable file
·100 lines (82 loc) · 2.57 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
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
94
95
96
97
98
99
100
#!/usr/bin/env python
import sys
import subprocess
import os
import os.path
import time
IMAGE = 'nefelinetworks/buildsrv'
BESS_DIR_HOST = os.path.dirname(os.path.abspath(__file__))
BESS_DIR_CONTAINER = '/build/bess'
BUILD_SCRIPT = './build.py'
def run_cmd(cmd):
proc = subprocess.Popen(cmd,
shell=True)
# err should be None
out, err = proc.communicate()
if proc.returncode:
print >> sys.stderr, 'Error has occured running host command: %s' % cmd
sys.exit(proc.returncode)
def run_docker_cmd(cmd):
run_cmd('docker run -t -v %s:%s %s %s' % \
(BESS_DIR_HOST, BESS_DIR_CONTAINER, IMAGE, cmd))
def build_bess():
run_docker_cmd('%s bess' % BUILD_SCRIPT)
def build_kmod():
kernel_ver = subprocess.check_output('uname -r', shell=True).strip()
try:
print 'Trying module build with the host kernel %s (optional)' % \
kernel_ver
run_docker_cmd('%s kmod' % BUILD_SCRIPT)
except:
print >> sys.stderr, '*** module build has failed.'
def build_kmod_buildtest():
kernels_to_test = 'linux-headers-*-generic'
run_docker_cmd("find /usr/src -name '%s' -exec bash -c " \
"'echo Building bessd module: {}; " \
"KERNELDIR={} %s kmod' \;" % \
(kernels_to_test, BUILD_SCRIPT))
def build_all():
build_bess()
build_kmod()
def do_clean():
run_docker_cmd('%s clean' % BUILD_SCRIPT)
def do_dist_clean():
run_docker_cmd('%s dist_clean' % BUILD_SCRIPT)
def print_usage():
print >> sys.stderr, \
'Usage: %s [all|bess|kmod|kmod_buildtest|clean|dist_clean|help]' % \
sys.argv[0]
def main():
os.chdir(BESS_DIR_HOST)
if len(sys.argv) == 1:
build_bess()
build_kmod()
elif len(sys.argv) == 2:
if sys.argv[1] == 'all':
build_all()
elif sys.argv[1] == 'bess':
build_bess()
elif sys.argv[1] == 'kmod':
build_kmod()
elif sys.argv[1] == 'kmod_buildtest':
build_kmod_buildtest()
elif sys.argv[1] == 'clean':
do_clean()
elif sys.argv[1] == 'dist_clean':
do_dist_clean()
elif sys.argv[1] == 'help':
print_usage()
sys.exit(0)
else:
print >> sys.stderr, 'Error - unknown command "%s".' % sys.argv[1]
print_usage()
sys.exit(2)
else:
print_usage()
sys.exit(2)
if __name__ == '__main__':
try:
main()
print 'Done.'
finally:
run_docker_cmd('chown --reference=. . -R')