|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import docker.errors |
| 4 | + |
| 5 | +sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))) |
| 6 | + |
| 7 | +import buildrunner.config.loader # noqa: E402 |
| 8 | +from buildrunner.docker.daemon import DAEMON_IMAGE_NAME # noqa: E402 |
| 9 | +from buildrunner import docker as buildrunner_docker # noqa: E402 |
| 10 | +from buildrunner import ( # noqa: E402 |
| 11 | + cli, |
| 12 | + __version__, |
| 13 | + BuildRunnerConfigurationError, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +def run_tests(argv, master_config_file=None, global_config_files=None): |
| 18 | + args = cli.parse_args(argv) |
| 19 | + |
| 20 | + # are we just printing the version? |
| 21 | + if args.print_version: |
| 22 | + print(__version__) |
| 23 | + return os.EX_OK |
| 24 | + |
| 25 | + global_config_files = global_config_files or [] |
| 26 | + if master_config_file: |
| 27 | + buildrunner.config.loader.MASTER_GLOBAL_CONFIG_FILE = master_config_file |
| 28 | + if not global_config_files or master_config_file != global_config_files[0]: |
| 29 | + global_config_files.insert(0, master_config_file) |
| 30 | + if global_config_files: |
| 31 | + buildrunner.config.DEFAULT_GLOBAL_CONFIG_FILES = global_config_files |
| 32 | + |
| 33 | + try: |
| 34 | + build_runner = cli.initialize_br(args) |
| 35 | + |
| 36 | + # Pull Docker daemon proxy |
| 37 | + image_name = f"{build_runner.buildrunner_config.global_config.docker_registry}/{DAEMON_IMAGE_NAME}" |
| 38 | + docker_client = buildrunner_docker.new_client( |
| 39 | + timeout=build_runner.docker_timeout |
| 40 | + ) |
| 41 | + docker_client.pull(image_name) |
| 42 | + |
| 43 | + build_runner.run() |
| 44 | + if build_runner.exit_code: |
| 45 | + return build_runner.exit_code |
| 46 | + except BuildRunnerConfigurationError as brce: |
| 47 | + print(str(brce)) |
| 48 | + return os.EX_CONFIG |
| 49 | + except docker.errors.ImageNotFound as inf: |
| 50 | + print(str(inf)) |
| 51 | + return os.EX_CONFIG |
| 52 | + return os.EX_OK |
0 commit comments