run-tests-docker.py 2.7 KB

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