run-tests-container.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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(
  21. "test_case", nargs="?", default="", help="Run the given test case"
  22. )
  23. parser.add_argument(
  24. "--fedora",
  25. action="store_true",
  26. help="Run the tests in fedora environment (DEFAULT)",
  27. )
  28. parser.add_argument(
  29. "--centos",
  30. action="store_true",
  31. help="Run the tests in centos environment",
  32. )
  33. parser.add_argument(
  34. "--skip-build",
  35. dest="skip_build",
  36. action="store_false",
  37. help="Skip building the container image",
  38. )
  39. parser.add_argument(
  40. "--shell",
  41. dest="shell",
  42. action="store_true",
  43. help="Gives you a shell into the container instead "
  44. "of running the tests",
  45. )
  46. return parser
  47. if __name__ == "__main__":
  48. parser = setup_parser()
  49. args = parser.parse_args()
  50. if args.centos is True:
  51. base_image = "centos:7"
  52. pkg_mgr = "yum"
  53. epel_pkg = "RUN yum -y install epel-release"
  54. infra_repo = (
  55. "ADD ./fedora-infra-tags.repo /etc/yum.repos.d/infra-tags.repo"
  56. )
  57. container_name = "pagure-test-centos"
  58. PKG_LIST += "python34 python34-coverage"
  59. else:
  60. base_image = "registry.fedoraproject.org/fedora:28"
  61. pkg_mgr = "dnf"
  62. container_name = "pagure-test-fedora"
  63. epel_pkg = ""
  64. infra_repo = ""
  65. with open(TEMPLATE, "r") as fp:
  66. t = Template(fp.read())
  67. with open("dev/docker/test_env", "w") as fp:
  68. fp.write(
  69. t.substitute(
  70. base_image=base_image,
  71. pkg_list=PKG_LIST,
  72. pkg_mgr=pkg_mgr,
  73. epel_pkg=epel_pkg,
  74. infra_repo=infra_repo,
  75. )
  76. )
  77. if args.skip_build is not False:
  78. print("------ Building Docker Image -----")
  79. sp.run(
  80. [
  81. "podman",
  82. "build",
  83. "--rm",
  84. "-t",
  85. container_name,
  86. "-f",
  87. "dev/docker/test_env",
  88. "dev/docker",
  89. ]
  90. )
  91. if args.shell:
  92. print("--------- Shelling in the container --------------")
  93. command = [
  94. "podman",
  95. "run",
  96. "-it",
  97. "--rm",
  98. "--name",
  99. container_name,
  100. "-v",
  101. "{}:/pagure".format(os.getcwd()),
  102. "--entrypoint=/bin/bash",
  103. container_name,
  104. ]
  105. sp.run(command)
  106. else:
  107. print("--------- Running Test --------------")
  108. sp.run(
  109. [
  110. "podman",
  111. "run",
  112. "-it",
  113. "--rm",
  114. "--name",
  115. container_name,
  116. "-v",
  117. "{}:/pagure".format(os.getcwd()),
  118. container_name,
  119. args.test_case,
  120. ]
  121. )