1
0

run-tests-docker.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #! /usr/bin/python3
  2. import argparse
  3. import os
  4. import subprocess as sp
  5. from string import Template
  6. TEMPLATE = 'dev/docker/test_env_template'
  7. PKG_LIST = 'python-alembic python-arrow python-binaryornot \ \n'\
  8. 'python-bleach python-blinker python-chardet python-cryptography \ \n'\
  9. 'python-docutils python-enum34 python-flask python2-fedora-flask \ \n'\
  10. 'python-flask-wtf python-flask-multistatic python2-bcrypt python-jinja2 \ \n'\
  11. 'python-markdown python-munch python-openid-cla python-openid-teams \ \n'\
  12. 'python-psutil python-pygit2 python-pygments python2-pillow \ \n'\
  13. 'python-sqlalchemy python-straight-plugin python-wtforms python-nose \ \n'\
  14. 'python-coverage python-mock python-mock python-eventlet python2-flask-oidc \ \n'\
  15. 'python-flake8 python-celery python-redis python-trollius python-beautifulsoup4 redis vim git'
  16. def setup_parser():
  17. """ Setup the cli arguments """
  18. parser = argparse.ArgumentParser(prog='pagure-test')
  19. parser.add_argument('test_case', nargs='?', default='',
  20. help='Run the given test case')
  21. parser.add_argument('--fedora', action='store_true',
  22. help='Run the tests in fedora environment (DEFAULT)')
  23. parser.add_argument('--centos', action='store_true',
  24. help='Run the tests in centos environment')
  25. parser.add_argument('--skip-build', dest='skip_build', action='store_false',
  26. help='Skip building the container image')
  27. return parser
  28. if __name__ == '__main__':
  29. parser = setup_parser()
  30. args = parser.parse_args()
  31. if args.centos is True:
  32. base_image = 'centos:7'
  33. pkg_mgr = 'yum'
  34. epel_pkg = 'RUN yum -y install epel-release'
  35. infra_repo = 'ADD ./fedora-infra-tags.repo /etc/yum.repos.d/infra-tags.repo'
  36. container_name = 'pagure-test-centos'
  37. else:
  38. base_image = 'registry.fedoraproject.org/fedora:27'
  39. pkg_mgr = 'dnf'
  40. container_name = 'pagure-test-fedora'
  41. epel_pkg = ''
  42. infra_repo = ''
  43. with open(TEMPLATE, 'r') as fp:
  44. t = Template(fp.read())
  45. with open('dev/docker/test_env', 'w') as fp:
  46. fp.write(t.substitute(base_image=base_image, pkg_list=PKG_LIST,
  47. pkg_mgr=pkg_mgr, epel_pkg=epel_pkg,
  48. infra_repo=infra_repo))
  49. if args.skip_build is not False:
  50. print('------ Building Docker Image -----')
  51. sp.run(['docker', 'build', '--rm', '-t', container_name, '-f',
  52. 'dev/docker/test_env', 'dev/docker'])
  53. print('--------- Running Test --------------')
  54. sp.run(['docker', 'run', '-it', '--rm', '--name', container_name, '-v',
  55. '{}:/code:z'.format(os.getcwd()), container_name, args.test_case])