def build_with_container_tool(args, arg_strings): """ Create a build image and run a build inside of container based on that image. """ if not args.container_tool: raise OpenCEError(Error.NO_CONTAINER_TOOL_FOUND) # env_config_file being positional argument cause problem while parsing known # arguments. Hence removing it from arg_strings, as it is anyway being read # from args ahead. for env_file in args.provided_env_files: if env_file in arg_strings: arg_strings.remove(env_file) parser = make_parser() _, unused_args = parser.parse_known_args(arg_strings[1:]) build_image_path, dockerfile = _generate_dockerfile_name(args.build_types, args.cuda_versions) if 'cuda' not in args.build_types or _capable_of_cuda_containers(args.cuda_versions): image_name = build_image(build_image_path, dockerfile, args.container_tool, args.cuda_versions if 'cuda' in args.build_types else None, args.container_build_args) else: raise OpenCEError(Error.INCOMPAT_CUDA, utils.get_driver_level(), args.cuda_versions) try: build_in_container(image_name, args, unused_args) 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(_home_path(args.container_tool), utils.DEFAULT_OUTPUT_FOLDER)), os.path.abspath(args.output_folder))
def build_runtime_container_image(args): """ Create a runtime image which will have a conda environment created using locally built conda packages and environment file. """ if not args.container_tool: raise OpenCEError(Error.NO_CONTAINER_TOOL_FOUND) local_conda_channel = os.path.abspath(args.local_conda_channel) if not os.path.exists(local_conda_channel): raise OpenCEError(Error.INCORRECT_INPUT_PATHS) if not os.path.exists(os.path.join(local_conda_channel, TEMP_FILES)): os.mkdir(os.path.join(local_conda_channel, TEMP_FILES)) for conda_env_file in parse_arg_list(args.conda_env_files): conda_env_file = os.path.abspath(conda_env_file) if not os.path.exists(conda_env_file): raise OpenCEError(Error.INCORRECT_INPUT_PATHS) # Copy the conda environment file into the TEMP_FILES dir inside local # conda channel with a new name and modify it conda_env_runtime_filename = os.path.splitext( os.path.basename(conda_env_file))[0] + '-runtime.yaml' conda_env_runtime_file = os.path.join(local_conda_channel, TEMP_FILES, conda_env_runtime_filename) create_copy(conda_env_file, conda_env_runtime_file) utils.replace_conda_env_channels(conda_env_runtime_file, r'file:.*', "file:/{}".format(TARGET_DIR)) image_version = utils.get_open_ce_version(conda_env_file) image_name = build_image(args.local_conda_channel, os.path.basename(conda_env_runtime_file), args.container_tool, image_version, args.container_build_args) print("Docker image with name {} is built successfully.".format( image_name)) cleanup(local_conda_channel)
def build_runtime_docker_image(args): """ Create a runtime image which will have a conda environment created using locally built conda packages and environment file. """ local_conda_channel = os.path.abspath(args.local_conda_channel) conda_env_file = os.path.abspath(args.conda_env_file) _validate_input_paths(local_conda_channel, conda_env_file) # Copy the conda environment file into the local conda channel to modify it shutil.copy(conda_env_file, local_conda_channel) conda_env_file = os.path.join(local_conda_channel, os.path.basename(conda_env_file)) utils.replace_conda_env_channels(conda_env_file, r'file:.*', "file:/{}".format(TARGET_DIR)) # Check if input local conda channel path is absolute if os.path.isabs(args.local_conda_channel): # make it relative to BUILD CONTEXT args.local_conda_channel = os.path.relpath(args.local_conda_channel, start=BUILD_CONTEXT) image_name = build_image(args.local_conda_channel, os.path.basename(conda_env_file)) print("Docker image with name {} is built successfully.".format(image_name))
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)