forked from tanium/octobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·49 lines (44 loc) · 1.72 KB
/
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
#!/usr/bin/env python
import os
import re
import shutil
import subprocess
is_travis = os.environ.get('TRAVIS') is not None
class task:
def __init__(self, title):
self.title = title
def __enter__(self):
if is_travis:
print "travis_fold:start:{}".format(self.title)
print ">> Starting {}".format(self.title)
return self
def __exit__(self, type, value, traceback):
print ">> Ending {}".format(self.title)
if is_travis:
print "travis_fold:end:{}".format(self.title)
def run(cmd, ignore_fail=False, quiet=False):
print ">> {}".format(cmd)
stdout = subprocess.PIPE if quiet else None
proc = subprocess.Popen(re.split('\s+', cmd), stdout=stdout, stderr=subprocess.STDOUT)
_, _ = proc.communicate()
retcode = proc.poll()
if retcode and not ignore_fail:
raise subprocess.CalledProcessError(retcode, cmd)
docker_tmp = './.docker-tmp'
docker_out = './.docker-tmp/bin'
if os.path.exists(docker_tmp):
shutil.rmtree(docker_tmp)
os.makedirs(docker_out)
with task("Dockerfile.build"):
run("docker build . -f Dockerfile.build -t octobot:build")
with task("run_tests"):
run("docker run -t --privileged --rm octobot:build")
with task("extract_files"):
run("docker rm -f extract", ignore_fail=True, quiet=True)
run("docker create --name extract octobot:build")
run("docker cp extract:/usr/src/app/target/release/octobot {}".format(docker_out))
run("docker cp extract:/usr/src/app/target/release/octobot-passwd {}".format(docker_out))
run("docker cp extract:/usr/src/app/target/release/octobot-ask-pass {}".format(docker_out))
run("docker rm -f extract")
with task("Dockerfile"):
run("docker build . -t octobot:latest")