/
docker_build.py
executable file
·66 lines (50 loc) · 2.07 KB
/
docker_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
#!/usr/bin/env python2.7
'''
Faraday Penetration Test IDE
Copyright (C) 2015 Infobyte LLC (http://www.infobytesec.com/)
See the file 'doc/LICENSE' for the license information
'''
import subprocess
import argparse
import re
import uuid
distros = ['debian:7.3', 'ubuntu:14.10']
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--cmd', help='Command to run')
parser.add_argument('-i', '--images', help='list of images')
parser.add_argument('-d', '--dockerfile', help='Command to run in the docker generation', default='extras/docker/Dockerfile.base')
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_args()
f = open(args.dockerfile)
baseDocker = f.read()
f.close()
if args.cmd:
if args.images:
with open(args.images) as f:
distros = f.read().splitlines()
print "Distros: " + str(distros)
for d in distros:
print "Start build docker: " + d
newDocker = re.sub("BUILDDISTRO", d, baseDocker)
file_ = open('docker.tmp', 'w')
file_.write(newDocker)
file_.close()
dockName = str(uuid.uuid4())[:13] + "_" + d
print "docker build -f docker.tmp -t " + str(dockName) + "."
try:
subprocess.call('docker build -f docker.tmp -t %s .' % dockName, shell=True)
try:
print "Run build docker: " + d + ", id: " + str(dockName)
print('./docker_launcher.py -d -t %s' % dockName)
print ('./docker_launcher.py -c \'%s\' -t %s' % (args.cmd , dockName))
subprocess.call('./docker_launcher.py -c "%s" -t %s' % (args.cmd , dockName), shell=True)
except subprocess.CalledProcessError, cpe:
print('Running faraday fail: "%s"' % cpe)
except subprocess.CalledProcessError, cpe:
print('build images error stop: "%s"' % cpe)
sys.exit(1)
else:
print "Usage -h",