2018-08-11 12:53:07 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
Build the Docker images used for testing.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import commands
|
|
|
|
import os
|
2018-08-11 18:00:02 +00:00
|
|
|
import tempfile
|
2018-08-11 12:53:07 +00:00
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
BASEDIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
def sh(s, *args):
|
|
|
|
if args:
|
|
|
|
s %= args
|
|
|
|
return shlex.split(s)
|
|
|
|
|
|
|
|
|
2018-08-11 18:00:02 +00:00
|
|
|
|
|
|
|
label_by_id = {}
|
|
|
|
|
|
|
|
for base_image, label in [('debian:stretch', 'debian'),
|
|
|
|
('centos:6', 'centos6'),
|
|
|
|
('centos:7', 'centos7')]:
|
|
|
|
args = sh('docker run --rm -it -d -h mitogen-%s %s /bin/bash',
|
|
|
|
label, base_image)
|
2018-08-11 12:53:07 +00:00
|
|
|
container_id = subprocess.check_output(args).strip()
|
2018-08-11 18:00:02 +00:00
|
|
|
label_by_id[container_id] = label
|
|
|
|
|
|
|
|
with tempfile.NamedTemporaryFile() as fp:
|
|
|
|
fp.write('[all]\n')
|
|
|
|
for id_, label in label_by_id.items():
|
|
|
|
fp.write('%s ansible_host=%s\n' % (label, id_))
|
|
|
|
fp.flush()
|
|
|
|
|
2018-08-11 12:53:07 +00:00
|
|
|
try:
|
|
|
|
subprocess.check_call(
|
|
|
|
cwd=BASEDIR,
|
2018-08-11 18:00:02 +00:00
|
|
|
args=sh('ansible-playbook -i %s -c docker setup.yml', fp.name),
|
2018-08-11 12:53:07 +00:00
|
|
|
)
|
|
|
|
|
2018-08-11 18:00:02 +00:00
|
|
|
for container_id, label in label_by_id.items():
|
|
|
|
subprocess.check_call(sh('''
|
|
|
|
docker commit
|
|
|
|
--change 'EXPOSE 22'
|
|
|
|
--change 'CMD ["/usr/sbin/sshd", "-D"]'
|
|
|
|
%s
|
|
|
|
mitogen/%s-test
|
|
|
|
''', container_id, label))
|
2018-08-11 12:53:07 +00:00
|
|
|
finally:
|
2018-08-11 18:00:02 +00:00
|
|
|
subprocess.check_call(sh('docker rm -f %s', ' '.join(label_by_id)))
|