Esempio n. 1
0
def test_docker_build_with_docker_build_args(mocker):
    '''
    Tests that docker build arguments are parsed and passed to docker build.
    '''
    build_args = "--build-arg ENV1=test1 --build-arg ENV2=test2 same_setting 0,1"

    arg_strings = [
        "path/to/open-ce", "build", "env", "--docker_build", "my-env.yaml",
        "--docker_build_args", build_args
    ]
    args = make_args()
    mocker.patch('os.system', return_value=0)

    docker_build.build_with_docker(args, arg_strings)
Esempio n. 2
0
def test_build_with_docker_failures(mocker):
    '''
    Failure cases for build_with_docker
    '''
    arg_strings = [
        "path/to/open-ce", "build", "env", "--docker_build", "my-env.yaml",
        "--cuda_versions", "10.2", "--build_types", "cuda"
    ]
    args = make_args()
    mocker.patch('os.system', return_value=1)

    with pytest.raises(OpenCEError) as exc:
        docker_build.build_with_docker(args, arg_strings)
    assert "Failure building image" in str(exc.value)
Esempio n. 3
0
def test_build_with_docker_incompatible_cuda_versions(mocker):
    '''
    Tests that passing incompatible value in --cuda_versions argument fails.
    '''
    arg_strings = [
        "path/to/open-ce", "build", "env", "--docker_build", "my-env.yaml",
        "--cuda_versions", "10.2", "--build_types", "cuda"
    ]
    args = make_args()

    mocker.patch('open_ce.docker_build._capable_of_cuda_containers',
                 return_value=0)
    mocker.patch('open_ce.utils.get_driver_level', return_value="abc")

    with pytest.raises(OpenCEError) as exc:
        docker_build.build_with_docker(args, arg_strings)
    assert "Driver level" in str(exc.value)
Esempio n. 4
0
def test_build_with_docker(mocker):
    '''
    Simple test for build_with_docker
    '''
    image_name = "my_image"
    arg_strings = [
        "path/to/open-ce", "build", "env", "--docker_build", "my-env.yaml",
        "--cuda_versions", "10.2", "--build_types", "cuda"
    ]
    args = make_args()
    mocker.patch('open_ce.docker_build.build_image',
                 return_value=(0, image_name))

    mocker.patch('open_ce.docker_build.build_in_container', return_value=0)

    mocker.patch('os.system', return_value=0)
    docker_build.build_with_docker(args, arg_strings)
Esempio n. 5
0
def build_env(args):
    '''Entry Function'''
    if args.docker_build:
        if len(args.cuda_versions.split(',')) > 1:
            raise OpenCEError(Error.TOO_MANY_CUDA)
        try:
            docker_build.build_with_docker(args, sys.argv)
        finally:
            for conda_env_file in glob.glob(
                    os.path.join(args.output_folder, "*.yaml")):
                utils.replace_conda_env_channels(
                    conda_env_file,
                    os.path.abspath(
                        os.path.join(docker_build.HOME_PATH,
                                     utils.DEFAULT_OUTPUT_FOLDER)),
                    os.path.abspath(args.output_folder))
        return

    # Checking conda-build existence if --docker_build is not specified
    utils.check_if_conda_build_exists()

    # Here, importing BuildTree is intentionally done after checking
    # existence of conda-build as BuildTree uses conda_build APIs.
    from open_ce.build_tree import BuildTree  # pylint: disable=import-outside-toplevel

    # If repository_folder doesn't exist, create it
    if args.repository_folder and not os.path.exists(args.repository_folder):
        os.mkdir(args.repository_folder)

    # Create the build tree
    build_tree = BuildTree(
        env_config_files=args.env_config_file,
        python_versions=inputs.parse_arg_list(args.python_versions),
        build_types=inputs.parse_arg_list(args.build_types),
        mpi_types=inputs.parse_arg_list(args.mpi_types),
        cuda_versions=inputs.parse_arg_list(args.cuda_versions),
        repository_folder=args.repository_folder,
        channels=args.channels_list,
        git_location=args.git_location,
        git_tag_for_env=args.git_tag_for_env,
        conda_build_config=args.conda_build_config,
        packages=inputs.parse_arg_list(args.packages))

    # Generate conda environment files
    conda_env_files = build_tree.write_conda_env_files(
        output_folder=os.path.abspath(args.output_folder),
        path=os.path.abspath(args.output_folder))
    print(
        "Generated conda environment files from the selected build arguments:",
        conda_env_files.values())
    print("INFO: One can use these environment files to create a conda" \
          " environment using \"conda env create -f <conda_env_file_name>.\"")

    if not args.skip_build_packages:
        # Build each package in the packages list
        for build_command in build_tree:
            if not _all_outputs_exist(args.output_folder,
                                      build_command.output_files):
                try:
                    print("Building " + build_command.recipe)
                    build_feedstock.build_feedstock_from_command(
                        build_command,
                        output_folder=os.path.abspath(args.output_folder),
                        conda_build_config=os.path.abspath(
                            args.conda_build_config))
                except OpenCEError as exc:
                    raise OpenCEError(Error.BUILD_RECIPE,
                                      build_command.repository,
                                      exc.msg) from exc
            else:
                print("Skipping build of " + build_command.recipe +
                      " because it already exists")

    if args.run_tests:
        _run_tests(build_tree, inputs.parse_arg_list(args.test_labels),
                   conda_env_files)