Blame dev/run-tests-docker.py

Clement Verna d6ad1e
#! /usr/bin/python3
Clement Verna d6ad1e
import argparse
Clement Verna d6ad1e
import os
Clement Verna d6ad1e
import subprocess as sp
Clement Verna d6ad1e
from string import Template
Clement Verna d6ad1e
Clement Verna d6ad1e
TEMPLATE = 'dev/docker/test_env_template'
Clement Verna d6ad1e
Clement Verna d6ad1e
PKG_LIST = 'python-alembic python-arrow python-binaryornot \ \n'\
Clement Verna d6ad1e
           'python-bleach python-blinker python-chardet python-cryptography \ \n'\
Clement Verna d6ad1e
           'python-docutils python-enum34 python-flask python2-fedora-flask \ \n'\
Clement Verna 431376
           'python-flask-wtf python-flask-multistatic python2-bcrypt python-jinja2 \ \n'\
Clement Verna d6ad1e
           'python-markdown python-munch python-openid-cla python-openid-teams \ \n'\
Clement Verna d6ad1e
           'python-psutil python-pygit2 python-pygments python2-pillow \ \n'\
Clement Verna d6ad1e
           'python-sqlalchemy python-straight-plugin python-wtforms python-nose \ \n'\
Clement Verna d6ad1e
           'python-coverage python-mock python-mock python-eventlet python2-flask-oidc \ \n'\
Clement Verna 431376
           'python-flake8 python-celery python-redis python-trollius python-beautifulsoup4 redis vim git'
Clement Verna d6ad1e
Clement Verna d6ad1e
Clement Verna d6ad1e
def setup_parser():
Clement Verna d6ad1e
    """ Setup the cli arguments """
Clement Verna d6ad1e
    parser = argparse.ArgumentParser(prog='pagure-test')
Clement Verna d6ad1e
    parser.add_argument('test_case', nargs='?', default='',
Clement Verna d6ad1e
                        help='Run the given test case')
Clement Verna d6ad1e
    parser.add_argument('--fedora', action='store_true',
Clement Verna d6ad1e
                        help='Run the tests in fedora environment (DEFAULT)')
Clement Verna d6ad1e
    parser.add_argument('--centos', action='store_true',
Clement Verna d6ad1e
                        help='Run the tests in centos environment')
Clement Verna d6ad1e
    parser.add_argument('--skip-build', dest='skip_build', action='store_false',
Clement Verna d6ad1e
                        help='Skip building the container image')
Clement Verna d6ad1e
Clement Verna d6ad1e
    return parser
Clement Verna d6ad1e
Clement Verna d6ad1e
Clement Verna d6ad1e
if __name__ == '__main__':
Clement Verna d6ad1e
    parser = setup_parser()
Clement Verna d6ad1e
    args = parser.parse_args()
Clement Verna d6ad1e
Clement Verna d6ad1e
    if args.centos is True:
Clement Verna d6ad1e
        base_image = 'centos:7'
Clement Verna d6ad1e
        pkg_mgr = 'yum'
Clement Verna d6ad1e
        epel_pkg = 'RUN yum -y install epel-release'
Clement Verna d6ad1e
        infra_repo = 'ADD ./fedora-infra-tags.repo /etc/yum.repos.d/infra-tags.repo'
Clement Verna d6ad1e
        container_name = 'pagure-test-centos'
Clement Verna d6ad1e
    else:
Clement Verna d6ad1e
        base_image = 'registry.fedoraproject.org/fedora:27'
Clement Verna d6ad1e
        pkg_mgr = 'dnf'
Clement Verna d6ad1e
        container_name = 'pagure-test-fedora'
Clement Verna d6ad1e
        epel_pkg = ''
Clement Verna d6ad1e
        infra_repo = ''
Clement Verna d6ad1e
Clement Verna d6ad1e
    with open(TEMPLATE, 'r') as fp:
Clement Verna d6ad1e
        t = Template(fp.read())
Clement Verna d6ad1e
    with open('dev/docker/test_env', 'w') as fp:
Clement Verna d6ad1e
        fp.write(t.substitute(base_image=base_image, pkg_list=PKG_LIST,
Clement Verna d6ad1e
                              pkg_mgr=pkg_mgr, epel_pkg=epel_pkg,
Clement Verna d6ad1e
                              infra_repo=infra_repo))
Clement Verna d6ad1e
Clement Verna d6ad1e
    if args.skip_build is not False:
Clement Verna d6ad1e
        print('------ Building Docker Image -----')
Clement Verna d6ad1e
        sp.run(['docker', 'build', '--rm', '-t', container_name, '-f',
Clement Verna d6ad1e
                'dev/docker/test_env', 'dev/docker'])
Clement Verna d6ad1e
Clement Verna d6ad1e
    print('--------- Running Test --------------')
Clement Verna d6ad1e
    sp.run(['docker', 'run', '-it', '--rm', '--name', container_name, '-v',
Clement Verna d6ad1e
            '{}:/code:z'.format(os.getcwd()), container_name, args.test_case])